标签:
-----decode行转列select name "姓名", sum(decode(subject, ‘语文‘, nvl(score, 0), 0)) "语文", sum(decode(subject, ‘数学‘, nvl(score, 0), 0)) "数学", sum(decode(subject, ‘英语‘, nvl(score, 0), 0)) "英语" from student_score group by name; ------ case when 行转列 select name "姓名", sum(case when subject=‘语文‘ then nvl(score,0) else 0 end) "语文", sum(case when subject=‘数学‘ then nvl(score,0) else 0 end) "数学", sum(case when subject=‘英语‘ then nvl(score,0) else 0 end) "英语" from student_score group by name;标签:
原文地址:http://www.cnblogs.com/lengzhijun/p/5658496.html