首先查看 http://apps.hi.baidu.com/share/detail/33163057
对于文章里面的查询一个月连续三天均有数据的电话号码的问题
解决办法是
SQL> select distinct msisdn from test a
2 where bill_month='200803'
3 and exists
4 ( select msisdn from test
5 where bill_month='200803' and msisdn=a.msisdn
6 start with day_number=a.day_number
7 connect by prior day_number=day_number-1 and prior msisdn= msisdn
8 group by msisdn
9 having count(*)>=3
10 );
其中最为关键的一点是为什么要在子查询里面写上group by msisdn having count(*)>=3
这是因为在递推查询中start with 字段是必须给一个值进行开始递推的条件
根据子查询的机制相当于循环条件,满足要求,更重要的是必须对每个值进行count的查询,只有满足查询个数大于3个的才满足查询需求
所有这里的组合必须放在子查询里面,保证对于每个start with的值都能满足需求才返回