以下是以sql server为例来说明:
select b.stu_name,
max(case a.subject when '语文' then a.grade else '' end) as 语文,
max(case a.subject when '数学' then a.grade else '' end) as 数学,
max(case a.subject when '英语' then a.grade else '' end) as 英语
from stu_grade a,stu_master b
where a.stu_no=b.stu_no
group by b.stu_name
数据库为oralce的话执行
select b.stu_name,
max(case a.subject when '语文' then to_char(a.grade) else '' end) as 语文,
max(case a.subject when '数学' then to_char(a.grade) else '' end) as 数学,
max(case a.subject when '英语' then to_char(a.grade) else '' end) as 英语
from stu_grade a,stu_master b
where a.stu_no=b.stu_no
group by b.stu_name
你的预期结果是:SELECT ... FROM ... 以后
查询的结果是:
Result
---------
510
3870
这样?
SELECT
GREATEST ( common, letter, year, matter, sick ) AS result
FROM
表
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)