数据库|mysql教程
sql查询,连续记录
数据库-mysql教程
能创建房间聊天室源码,vscode如何使用vue框架,有道词典ubuntu安装,tomcat哪个好,sqlite 块,分屏网页设计,sdcms企业版1.3 数据库连接失败,织梦 服务器上手动发布图片,wordpress文章摘要插件,hippy前端框架,爬虫octo,php 判断json,公众号需要seo,安卓Springboot,dede首页标签,php注入某大型网站,网页视频放在html里面的代码,互联网公司市场规划模板,后台弹出网页实现多选,特效html页面源码下载,分类信息管理系统源码,一 学生信息管理程序 amplzw
有这样一个需求:需要查询出某个客户某一年那些天是有连续办理过业务,本文给予sql实现语句并测试,感兴趣的朋友可以了解下
菠菜php源码 免费,ubuntu更新无法远程,爬虫怎么用python,寺院php源码,天津seo计费lzw
php 微信相册制作源码,将vscode安装虚拟机,ubuntu 命令语句,tomcat 哈希冲突计算,qq人民爬虫,天津php招聘,荆门产品seo推广怎么做lzw
需求说明:
需要查询出某个客户某一年那些天是有连续办理过业务
实现SQL如下:
创建表:
代码如下:
create table test_num
(tyear number,
tdate date);
测试数据:
insert into test_num
select ,trunc(sysdate)-1 from dual union all
select ,trunc(sysdate)-002 from dual union all
select ,trunc(sysdate)-003 from dual union all
select ,trunc(sysdate)-004 from dual union all
select ,trunc(sysdate)-005 from dual union all
select ,trunc(sysdate)-007 from dual union all
select ,trunc(sysdate)-008 from dual union all
select ,trunc(sysdate)-009 from dual union all
select ,trunc(sysdate)-120 from dual union all
select ,trunc(sysdate)-121 from dual union all
select ,trunc(sysdate)-122 from dual union all
select ,trunc(sysdate)-124 from dual union all
select ,trunc(sysdate)-125 from dual union all
select ,trunc(sysdate)-127 from dual union all
select ,trunc(sysdate)-099 from dual union all
select ,trunc(sysdate)-100 from dual union all
select ,trunc(sysdate)-101 from dual union all
select ,trunc(sysdate)-102 from dual union all
select ,trunc(sysdate)-104 from dual union all
select ,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)
GROUP BY TYEAR, GNUM
ORDER BY TYEAR, MIN(TDATE)