我有一个查询,在每天的1/3/7/14/30/60天不同时段汇总数据。
看起来像这样:
SELECT REGION, CUSTOMER, SYSDATE AS SNAPSHOT_DAY
, COUNT (CASE WHEN HIT_DAY >= SYSDATE -60 THEN SESSION END ) AS D60_SESSS_CNT
, COUNT (CASE WHEN HIT_DAY >= SYSDATE -30 THEN SESSION END ) AS D30_SESSS_CNT
, COUNT (CASE WHEN HIT_DAY >= SYSDATE -14 THEN SESSION END ) AS D14_SESSS_CNT
, COUNT (CASE WHEN HIT_DAY >= SYSDATE -7 THEN SESSION END ) AS D7_SESSS_CNT
, COUNT (CASE WHEN HIT_DAY >= SYSDATE -3 THEN SESSION END ) AS D3_SESSS_CNT
, COUNT (CASE WHEN HIT_DAY >= SYSDATE -1 THEN SESSION END ) AS D1_SESSS_CNT
我想创建一个包含聚合信息的表格,我想要回溯3个月,以便如果您要select* from table where cusomter = 1234
REGION | CUSTOMER | SNAPSHOT_DAY | D60_SESSS_CNT| D30_SESSS_CNT| etc...
1 | 1234 | today | x | x |
1 | 1234 | yesterday | x | x |
.
.
1 | 1234 | today -90 | x | x |
我尝试了几个不同的版本,我不确定为什么似乎没有任何问题。