oracle—SQL技巧之(一)连续记录查询sql案例测试建站
导读:1建站知识有这样一个需求:需要查询出某个客户某一年那些天是有连续办理过业务,本文给予sql实现语句并测试,感兴趣的朋友网站推广优化seo网站建设制作。
需求说明: 需要查询出某个客户某一年那些天是有连续办理过业务 实现SQL如下: 创建表:
复制代码 代码如下:
create table test_num (tyear number, tdate date);
测试数据: insert into test_num select 2014,trunc(sysdate)-1 from dual union all select 2014,trunc(sysdate)-002 from dual union all select 2014,trunc(sysdate)-003 from dual union all select 2014,trunc(sysdate)-004 from dual union all select 2014,trunc(sysdate)-005 from dual union all select 2014,trunc(sysdate)-007 from dual union all select 2014,trunc(sysdate)-008 from dual union all select 2014,trunc(sysdate)-009 from dual union all select 2013,trunc(sysdate)-120 from dual union all select 2013,trunc(sysdate)-121 from dual union all select 2013,trunc(sysdate)-122 from dual union all select 2013,trunc(sysdate)-124 from dual union all select 2013,trunc(sysdate)-125 from dual union all select 2013,trunc(sysdate)-127 from dual union all select 2015,trunc(sysdate)-099 from dual union all select 2015,trunc(sysdate)-100 from du网站建设al union all select 2015,trunc(sysdate)-101 from dual union all select 2015,trunc(sysdate)-102 from dual union all select 2015,trunc(sysdate)-104 from dual union all select 2015,trunc(sysdate)-105 from dual; 写SQL:复制代码 代码如下:
SELECT TYEAR, MIN(TDATE) AS STARTDATE, MAX(TDATE), COUNT(TYEAR) AS ENDNUM FROM (SELECT A.*, A.TDATE - ROWNUM AS GNUM FROM (SELECT * FROM TEST_NUM ORDER BY TYEAR, TDATE) A) GRO网站建设哪家好UP BY TYEAR, G百度seo网站优化NUM ORDER BY TYEAR, MIN(TDATE)
相关网站推广优化seo网站建设制作。声明: 本文由我的SEOUC技术文章主页发布于:2023-05-24 ,文章oracle—SQL技巧之(一)连续记录查询sql案例测试建站主要讲述案例,标签,SQL网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/web_6623.html