基本用法~~~~~~~~~~~~~~~~~~~~~~sql
SELECT * FROM tree -- where 子句 , 如有,只是過濾最終結果的做用 START WITH father = '爺爺' -- 從 father 爲 '爺爺' 的 那一條記錄開始 -- 如有 nocyle 關鍵字, 則不走環, 僅列出全部映射 CONNECT BY [NOCYCLE] PRIOR son = father; -- 你的 son 爲 他人的 father, 搜索他人,即往下找
實際例子~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
問題:
數據庫裏有字段day_number,msisdn。如何寫月度連續3天有記錄的手機號?表結構以下:
BILL_MONTH DAY_NUMBER MSISDN
-------------------- ---------- --------------------
200803 1 1380000000
200803 3 1380000000
200803 2 1380000000
200803 2 1380100000
200803 4 1380400000
200803 5 1380400000
表中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 );