参考:
select 姓名
,sum(case when 学期='第一学期' and 课程='物理' and 考试类型='期中' then 成绩 end) 第一学期期中物理
,sum(case when 学期='第一学期' and 课程='化学' and 考试类型='期中' then 成绩 end) 第一学期期中化学
....
,sum(case when 学期='第二学期' and 课程='物理' and 考试类型='期中' then 成绩 end) 第二学期期中物理
.....
,sum(case when 学期='第一学期' and 课程='物理' and 考试类型='会考' then 成绩 end) 第一学期会考物理
....
from 成绩总表 group by 姓名
解决方案 »
- 2000的bak文件还原问题
- 怎样用一条语句按日期查询多个表中相同字段的记录之和
- 日志问题,高分求助
- 一个数据库查询速度的问题
- 存储过程中能不能用表参数?
- 急需技术经理,高薪诚聘,详情请见我公司CSDN招聘页面http://job.csdn.net/Jobs/de9a50727e4d45cfa5002085f4c4a84b/ViewCompany.aspx
- 怎样把两个表(或者视图)中的相同的行找出来
- 我有一个查询要问?比较难。请教大家了。谢谢!
- SQL数据库恢复出错
- 每个班的选课门数(班级名称、选课门数、课程名称),求具体的思路和代码
- 各位大哥,我有一个关于cursor的问题,想要请教,谢谢了,在线等待
- 做网站用ASP+SQL Server的高手请进来~
Select (case when 课程 = '物理' then 成绩 else 0 end) as 物理,
(case when 课程 = '化学' then 成绩 else 0 end) as 化学,
学期,考试日期
where 考试类型 = '期中'
group by 学期,考试日期
2:
Select (case when 课程 = '物理' then 成绩 else 0 end) as 物理,
(case when 课程 = '化学' then 成绩 else 0 end) as 化学,
学期,考试日期
where 考试类型 = '期末'
group by 学期,考试日期
3:
Select (case when 课程 = '物理' then 成绩 else 0 end) as 物理,
(case when 课程 = '化学' then 成绩 else 0 end) as 化学,
学期,考试日期
where 考试类型 = '会考'
group by 学期,考试日期
or
select * from (
Select (case when 课程 = '物理' then 成绩 else 0 end) as 物理,
(case when 课程 = '化学' then 成绩 else 0 end) as 化学,
学期,考试日期
where 考试类型 = '期中'
group by 学期,考试日期
union all
Select (case when 课程 = '物理' then 成绩 else 0 end) as 物理,
(case when 课程 = '化学' then 成绩 else 0 end) as 化学,
学期,考试日期
where 考试类型 = '期末'
group by 学期,考试日期
union all
Select (case when 课程 = '物理' then 成绩 else 0 end) as 物理,
(case when 课程 = '化学' then 成绩 else 0 end) as 化学,
学期,考试日期
where 考试类型 = '会考'
group by 学期,考试日期
) temp
order by 考试类型
group by '学期','考试日期','课程'就能到这个程度了吧