日期:2014-05-17 浏览次数:20997 次
SQL> WITH t AS ( 2 SELECT TO_DATE('2011-11-09 05:34:21','yyyy-mm-dd hh24:mi:ss') lasttime,'1-2591' tagid FROM DUAL UNION ALL 3 SELECT TO_DATE('2011-11-09 07:10:43','yyyy-mm-dd hh24:mi:ss') lasttime,'1-2591' tagid FROM DUAL UNION ALL 4 SELECT TO_DATE('2011-11-09 19:44:15','yyyy-mm-dd hh24:mi:ss') lasttime,'1-2591' tagid FROM DUAL UNION ALL 5 SELECT TO_DATE('2011-11-09 19:44:20','yyyy-mm-dd hh24:mi:ss') lasttime,'1-2591' tagid FROM DUAL UNION ALL 6 SELECT TO_DATE('2011-11-09 19:44:22','yyyy-mm-dd hh24:mi:ss') lasttime,'1-2591' tagid FROM DUAL UNION ALL 7 SELECT TO_DATE('2011-11-09 19:45:27','yyyy-mm-dd hh24:mi:ss') lasttime,'1-2591' tagid FROM DUAL UNION ALL 8 SELECT TO_DATE('2011-11-09 19:45:29','yyyy-mm-dd hh24:mi:ss') lasttime,'1-2590' tagid FROM DUAL 9 ) 10 SELECT m.lasttime, 11 m.tagid 12 FROM (SELECT t.*, 13 COUNT(*) OVER(PARTITION BY tagid ORDER BY lasttime RANGE BETWEEN CURRENT ROW AND INTERVAL '4' minute following) cnt 14 FROM t) m 15 WHERE m.cnt = 1 16 ; LASTTIME TAGID ----------- ------ 2011/11/09 1-2590 2011/11/09 1-2591 2011/11/09 1-2591 2011/11/09 1-2591