Sql 在oracle中按天数连续检索记录
我想检索一天中现金存款超过4到1000000的记录,并持续5天以上 我提出了以下问题Sql 在oracle中按天数连续检索记录,sql,oracle,Sql,Oracle,我想检索一天中现金存款超过4到1000000的记录,并持续5天以上 我提出了以下问题 SELECT COUNT(a.txamt) AS "txcount" , SUM(a.txamt) AS "txsum" , b.custcd , a.txdate FROM tb_transactions a INNER JOIN tb_accounts b ON a.acctno = b.acctno
SELECT COUNT(a.txamt) AS "txcount"
, SUM(a.txamt) AS "txsum"
, b.custcd
, a.txdate
FROM tb_transactions a
INNER JOIN tb_accounts b
ON a.acctno = b.acctno
WHERE a.cashflowtype = 'CR'
GROUP BY b.custcd, a.txdate
HAVING COUNT(a.txamt)>4 and SUM(a.txamt)>='1000000'
ORDER BY a.txdate;
但是,如果这种模式持续5天,我就无法找到记录
如何达到预期的效果?类似于:
SELECT *
FROM (
SELECT t.*,
COUNT( txdate ) OVER ( PARTITION BY custcd
ORDER BY txdate
RANGE BETWEEN INTERVAL '0' DAY PRECEDING
AND INTERVAL '4' DAY FOLLOWING ) AS
num_days
FROM (
select count(a.txamt) as "txcount",
sum(a.txamt) as "txsum",
b.custcd,
a.txdate
from tb_transactions a inner join tb_accounts b on a.acctno=b.acctno
where a.cashflowtype='CR'
group by b.custcd, a.txdate
having count(a.txamt)>4 and sum(a.txamt)>=1000000
) t
)
WHERE num_days = 5
order by a.txdate;
这是什么意思?“一天内现金存款超过4笔,总计1000000笔,并持续5天以上”。样本数据和预期结果将有所帮助。