我写了以下查询,但它在运行总计中没有用 专栏,我需要下面提到的日期和每个ID的所有记录,我 前21天需要累计总数和21天的记录数 天,在oracle中执行
SELECT (TO_DATE (MIN (date_ref_key), 'YYYYMMDD')),
id,
(TO_DATE (MIN (date_ref_key), 'YYYYMMDD')) + 21,
SUM (
Deposit_Amount)
OVER (PARTITION BY id
ORDER BY (TO_DATE (MIN (date_ref_key), 'YYYYMMDD')) <(to_date(min(date_ref_key),'YYYYMMDD'))+21) running_total
from performance.fact_paymentsystems@cis_prod_link
WHERE sort='Deposit' and
date_ref_key>=20140831 and date_ref_key<20160901
and status='Done'
GROUP BY ID
order by min(date_ref_key)
输入
id date_ref_key Amount
1 01/09/2014 10
1 02/09/2014 10
1 03/09/2014 10
1 04/09/2014 10
1 05/09/2014 10
1 06/09/2014 10
1 07/09/2014 10
1 08/09/2014 10
1 09/09/2014 10
1 10/09/2014 10
1 11/09/2014 10
1 12/09/2014 10
1 13/09/2014 10
1 14/09/2014 10
1 15/09/2014 10
1 16/09/2014 10
1 17/09/2014 10
1 18/09/2014 10
1 19/09/2014 10
1 20/09/2014 10
1 21/09/2014 10
1 22/09/2014 10
1 23/09/2014 10
1 24/09/2014 10
2 01/09/2014 10
2 02/09/2014 10
2 01/09/2012 10
2 02/09/2012 10
2 03/09/2012 10
2 04/09/2012 10
2 05/09/2012 10
2 06/09/2012 10
2 07/09/2012 10
2 08/09/2012 10
2 09/09/2012 10
2 10/09/2012 10
2 11/09/2012 10
2 12/09/2012 10
2 13/09/2012 10
2 14/09/2012 10
2 15/09/2012 10
2 16/09/2012 10
2 17/09/2012 10
2 18/09/2012 10
2 19/09/2012 10
2 20/09/2012 10
2 21/09/2012 10
2 22/09/2012 10
3 01/01/2015 10
3 02/01/2015 10
3 03/01/2015 10
3 04/01/2015 10
3 05/01/2015 10
3 06/01/2015 10
3 07/01/2015 10
3 08/01/2015 10
3 09/01/2015 10
3 10/01/2015 10
3 11/01/2015 10
3 12/01/2015 10
3 13/01/2015 10
3 14/01/2015 10
3 15/01/2015 10
3 16/01/2015 10
3 17/01/2015 10
3 18/01/2015 10
3 19/01/2015 10
3 20/01/2015 10
3 21/01/2015 10
3 22/01/2015 10
3 23/01/2015 10
3 24/01/2015 10
输出
ID Amount COUNTOF IDS'S (SHOULD ALSO COUNT DUPLICATES IF PRESENT)
1 210 21
3 210 21