基本用法~~~~~~~~~~~~~~~~~~~~~~
SELECT * FROM tree
-- where 子句 , 若有,只是过滤最终结果的作用
START WITH father = '爷爷' -- 从 father 为 '爷爷' 的 那一条记录开始
-- 若有 nocyle 关键字, 则不走环, 仅列出所有映射
CONNECT BY [NOCYCLE] PRIOR son = father; -- 你的 son 为 他人的 father, 搜索他人,即往下找
问题:
数据库里有字段day_number,msisdn。如何写月度连续3天有记录的手机号?表结构如下:
BILL_MONTH
-------------------- ---------- --------------------
200803
200803
200803
200803
200803
200803
表中3月份连续3天有记录的纪录就是1380000000。请问如何写这样的sql?
select distinct msisdn from test a
where bill_month='200803'
and exists
(
select msisdn from test
where bill_month='200803' and msisdn=a.msisdn
start with day_number=a.day_number
connect by prior day_number=day_number-1 and prior msisdn= msisdn
group by msisdn
having count(*)>=3
);
本博客详细介绍了如何使用SQL查询语句筛选出2008年3月期间,每天都有记录的特定手机号,通过连接条件和聚合函数实现连续三天记录的统计。

1万+

被折叠的 条评论
为什么被折叠?



