Oracle根据【日期】组,其他条件根据PIVOT行转列。使每个日期条件关联的其他数据只有一行。

  
  select 
  OPER_TIME,
  MICROPAY,
  REFUND
  from
  (
  select trunc(oper_time) oper_time, 
  class_name,
  sum(total_fee) total_fee
  from wx_pay_detail
  group by trunc(oper_time),class_name
  )
  pivot(sum(total_fee) for class_name in 
  ('MicroPay'as "MICROPAY",'Refund' as "REFUND"))
  order by oper_time

  

↑SQL,转换后列名 在FOR...IN 中AS 想要的 “名称”

posted @ 2017-11-23 15:42  歌·颂  阅读(837)  评论(0编辑  收藏  举报