sql 列转换成行

表的数据如下:
sql 列转换成行
我想用sql语句查询出的结果是这样:
 

sql语句如下:
select c_e_Num,sum(case c_cw_Num when 'cw1' then c_Number else '' end) as cw1,

sum(case c_cw_Num when 'cw2' then c_Number else '' end) as cw2,

sum(case c_cw_Num when 'cw3' then c_Number else '' end) as cw3,

sum(case c_cw_Num when 'cw4' then c_Number else '' end) as cw4,

sum(case c_cw_Num when 'cw5' then c_Number else '' end) as cw5

from tb_cworkcount GROUP BY c_e_Num

运行效果如下:

你可能感兴趣的:(sql)