码迷,mamicode.com
首页 > 其他好文 > 详细

orcle行转列

时间:2016-07-10 21:51:40      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

-----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;

orcle行转列

标签:

原文地址:http://www.cnblogs.com/lengzhijun/p/5658496.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!