用上面那张表的数据生成下面这张表,SQL该怎么写。多谢!作者: aman_cao 时间: 2011-7-28 10:30
select name as 姓名,max(case when subject='语文' then result else '' end) as `语文`, max(case when subject='数学' then result else '' end) as `数学`, max(case when subject='英语' then result else '' end) as `英语` from stu GROUP BY name
Mysql下的行转列,mssql或oracle的自己找吧作者: jzf2050 时间: 2011-8-17 20:24
select distinct 学生,
(select distinct 成绩 from student where 科目='语文' and 学生 like a.学生) as 语文,
(select distinct 成绩 from student where 科目='数学' and 学生 like a.学生) as 数学,
(select distinct 成绩 from student where 科目='英语' and 学生 like a.学生) as 英语
from student a