---原始数据
-- 以下结果是运行:(将连续的数据通过RN展示表示是一组数据)
SELECT OCCUR_DATE,SITE_NO,VOUH_NO,ACCOUNT,TRUNC(T.OCCUR_DATE-ROW_NUMBER() OVER(PARTITION BY T.ACCOUNT ORDER BY T.OCCUR_DATE)) RN
FROM TEMP_225 T
/*求出连续三天都符合条件的数据,如果有一天不连续,即不取出*/
最终语句
SELECT ACCOUNT,OCCUR_DATE,START_DATE,END_DATE,AMOUNT,TX_NUM FROM(
SELECT ACCOUNT,(SELECT DATA_DATE FROM MC_DATA_DATE) OCCUR_DATE,MIN(OCCUR_DATE) START_DATE,MIN(SITE_NO)SITE_NO,MAX(OCCUR_DATE) END_DATE,TO_NUMBER(SUM(VOUH_NO)) AMOUNT,COUNT(1)TX_NUM FROM (
SELECT OCCUR_DATE,TRUNC(T.OCCUR_DATE-ROW_NUMBER() OVER(PARTITION BY T.ACCOUNT ORDER BY T.OCCUR_DATE)) RN
FROM TEMP_225 T
)GROUP BY ACCOUNT,RN
HAVING COUNT(1)>=3
)
----以下结果是运行
原文链接:https://www.f2er.com/oracle/213437.html