oracle按照日期求连续天数的数据sql

前端之家收集整理的这篇文章主要介绍了oracle按照日期求连续天数的数据sql前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

---原始数据

@H_404_3@

-- 以下结果是运行:(将连续的数据通过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@H_404_3@ FROM TEMP_225 T@H_404_3@

@H_404_3@

@H_404_3@

@H_404_3@

/*求出连续三天都符合条件的数据,如果有一天不连续,即不取出*/@H_404_3@

最终语句

SELECT ACCOUNT,OCCUR_DATE,START_DATE,END_DATE,AMOUNT,TX_NUM FROM(@H_404_3@ 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 (@H_404_3@ @H_404_3@ SELECT OCCUR_DATE,TRUNC(T.OCCUR_DATE-ROW_NUMBER() OVER(PARTITION BY T.ACCOUNT ORDER BY T.OCCUR_DATE)) RN@H_404_3@ FROM TEMP_225 T@H_404_3@ )GROUP BY ACCOUNT,RN@H_404_3@ HAVING COUNT(1)>=3@H_404_3@ )

@H_404_3@

----以下结果是运行@H_404_3@

原文链接:https://www.f2er.com/oracle/213437.html

猜你在找的Oracle相关文章