根据日期时间将列分隔为多列

时间:2018-11-08 11:29:12

标签: sql oracle

我有以下数据集

TRAN_DT;               CONENT; TYPE
01/01/2018 12:00:00;   AAA   ; 1
01/01/2018 12:00:00;   AAA   ; 2
01/01/2018 12:00:00;   AAA   ; 3
01/01/2018 01:00:00;   FFF   ; 1
01/01/2018 01:00:00;   FFF   ; 2

我需要我的结果像

    01/01/2018 12:00:00;01/01/2018 01:00:00
  1 AAA                ;FFF 
  2 AAA                ;FFF
  3 AAA

谢谢。

1 个答案:

答案 0 :(得分:1)

我认为您需要条件聚合:

select type, 
       max(case when tran_dt = '01/01/2018 12:00:00' then conent end) as c_20180101_12,
       max(case when tran_dt = '01/01/2018 01:00:00' then conent end) as c_20180101_01
from t
group by type
order by type;