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 想要的 “名称”

原文地址:https://www.cnblogs.com/Early-Bird/p/7885217.html