本文介绍了TD中的PIVOT实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想透视我的数据,并且我知道我们在teradata 16中具有透视功能.我不确定如何使用它.我知道其他方法,例如max(case ...),但是我的数据集很大,所以我不能使用它.
I want to pivot my data and i am aware that we have Pivot function in teradata 16.I am not sure how to use it. I am aware of other methods like max(case...) but my data set is large so i can't use that.
任何人都可以在这里告诉我如何使用数据透视:
Can anyone tell me how to use pivot here:
SERV_PROVIDER_ID CALL_START_DT cnt1
50003 4/15/2018 25,117
50003 4/16/2018 65,630
50003 4/17/2018 63,880
50003 4/18/2018 40,080
想要
SERV_PRIDER_ID CALL_START_DT1 CNT1 CALL_START_DT2 CNT2 CALL_START_DT3 CNT3
我只需要4天的数据.
感谢您的帮助.
推荐答案
知道这四个日期时:
SELECT *
FROM mytab
PIVOT
( Sum(cnt1)
FOR CALL_START_DT
IN (DATE'2018-04-15'
,DATE'2018-04-16'
,DATE'2018-04-17'
,DATE'2018-04-18'
)
) AS dt;
但是您的预期结果看起来像是您希望动态地拥有那些日子:
But your expected result looks like you want those days dynamically:
WITH cte AS
(
SELECT t.*,
Row_Number()
Over (PARTITION BY SERV_PROVIDER_ID
ORDER BY CALL_START_DT) AS rn
FROM mytab AS t
)
SELECT *
FROM cte
PIVOT
( Min(CALL_START_DT) AS CALL_START_DT,
Sum(cnt1) AS Cnt
FOR rn
IN (1
,2
,3
,4
)
) AS dt;
这篇关于TD中的PIVOT实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!