繁体   English   中英

Teradata SQL 中的汇总表

[英]Summary table in Teradata SQL

我在 Teradata SQL 中有下表,称为 transactions_data:

User_ID      Trans_Date      Amount Purchased
 3134        2012-08-12            3.35
 3135        2012-08-12            4.47
 3134        2012-08-13            4.45

我要做的是创建一个表,其中的列涵盖表中的所有日期,行是每个用户当天花费的金额,例如:

User_ID       2012-08-12      2012-08-13      2012-08-14
 3134            3.35             4.47            0
 3135            4.47               0             0

在 Teradata 中是否有有效的方法来执行此操作,尤其是如果总共有 365 个日期(即一年的日期或 2 年的日期?)

谢谢你。

如果您事先知道日期列表,则可以使用条件聚合:

select user_id,
    max(case when trans_date = '2012-08-12' then amount_purchased end) as amount_2012_08_12,
    max(case when trans_date = '2012-08-13' then amount_purchased end) as amount_2012_08_13,
    ...
from mytable
group by user_id
    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM