日期:2014-05-17 浏览次数:20952 次
WITH t AS (
SELECT '甲' person, 'a' position, '17:00' begintime, '17:10' endtime FROM dual UNION ALL
SELECT '甲' person, 'a' position, '17:10' begintime, '17:30' endtime FROM dual UNION ALL
SELECT '甲' person, 'a' position, '17:30' begintime, '17:35' endtime FROM dual UNION ALL
SELECT '甲' person, 'b' position, '17:35' begintime, '17:40' endtime FROM dual UNION ALL
SELECT '甲' person, 'a' position, '17:40' begintime, '18:10' endtime FROM dual)
SELECT a.person,
a.position,
MIN(a.begintime) begintime,
MAX(a.endtime) endtime
FROM t a
START WITH NOT EXISTS (SELECT 1
FROM t b
WHERE b.person = a.person
AND b.position = a.position
AND b.endtime = a.begintime)
CONNECT BY PRIOR a.endtime = a.begintime
AND PRIOR a.person = a.person
AND PRIOR a.position = a.position
GROUP BY a.person, a.position, ROWNUM - LEVEL
ORDER BY 1, 3;