日期:2014-05-17 浏览次数:20828 次
with test as(
SELECT 'jack' ACCOUNT,sysdate LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+1 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+2 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+4 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+5 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+6 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+7 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+8 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+9 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+10 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+11 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+12 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+13 LoginDate FROM dual union all
SELECT 'jack' ACCOUNT,sysdate+14 LoginDate FROM dual union all
SELECT 'tom' ACCOUNT,sysdate+1 LoginDate FROM dual union all
SELECT 'tom' ACCOUNT,sysdate+2 LoginDate FROM dual union all
SELECT 'tom' ACCOUNT,sysdate+4 LoginDate FROM dual union all
SELECT 'tom' ACCOUNT,sysdate+5 LoginDate FROM dual
)
SELECT distinct ACCOUNT
FROM (SELECT ACCOUNT,
LoginDate,
LoginDate - DENSE_RANK() OVER(PARTITION BY ACCOUNT ORDER BY LoginDate) FLAG
FROM test)
group by ACCOUNT, FLAG
having count(1) > 10