当前位置: 代码迷 >> SQL >> sql 行转列,运用case when then
  详细解决方案

sql 行转列,运用case when then

热度:35   发布时间:2016-05-05 15:08:16.0
sql 行转列,使用case when then

?

行转列,使用case when then

?

		select			date,			sum(case c.type when 'try-pay' then c.sum else 0 end ) as 'try-pay',			sum(case c.type when 'pay-real' then c.sum else 0 end )as 'pay-real',			sum(case c.type when 'pay-success' then c.sum else 0 end )as 'pay-success',			sum(case c.type when 'pay-failure' then c.sum else 0 end )as 'pay-failure',			sum(case c.type when 'notify-input' then c.sum else 0 end )as 'notify-input',			sum(case c.type when 'normal-query' then c.sum else 0 end )as 'normal-query'					from			(SELECT sum(f_count) as sum ,f_type as type ,f_date as date FROM t_log_analyse			 group by f_type,f_date order by f_date desc) 		as c					group by date

?

?

  相关解决方案