我正在尝试查找带有中断处理日期的给定值的以下数据的最小和最大处理日期(请注意,周末不处理行,如果它们具有相同的值,我不想将它们分成两个不同的集合)
SELECT 1, 'A',to_date('10/01/2012','dd/mm/yyyy'), 10, to_date('11/01/2012','dd/mm/yyyy') FROm DUAL
UNION ALL SELECT 1, 'A',to_date('11/01/2012','dd/mm/yyyy'), 10, to_date('12/01/2012','dd/mm/yyyy') FROm DUAL
UNION ALL SELECT 1, 'A',to_date('12/01/2012','dd/mm/yyyy'), 9, to_date('13/01/2012','dd/mm/yyyy') FROm DUAL
UNION ALL SELECT 1, 'A',to_date('13/01/2012','dd/mm/yyyy'), 9, to_date('14/01/2012','dd/mm/yyyy') FROm DUAL
UNION ALL SELECT 1, 'A',to_date('16/01/2012','dd/mm/yyyy'), 9, to_date('17/01/2012','dd/mm/yyyy') FROm DUAL
UNION ALL SELECT 1, 'A',to_date('17/01/2012','dd/mm/yyyy'), 10, to_date('18/01/2012','dd/mm/yyyy') FROm DUAL
UNION ALL SELECT 1, 'A',to_date('18/01/2012','dd/mm/yyyy'), 10, to_date('19/01/2012','dd/mm/yyyy') FROm DUAL;
我的尝试(我知道这是错误的)
SELECT id, cd, value, min(p_dt) min_dt, max(p_dt) max_dt FROM T
group by id, cd, value;
这返回
ID CD VALUE MIN_DT MAX_DT
----------------------------------------------------------------------------------
1 A 9 January, 12 2012 00:00:00+0000 January, 16 2012 00:00:00+0000
1 A 10 January, 10 2012 00:00:00+0000 January, 18 2012 00:00:00+0000
我想要返回的是
ID CD VALUE MIN_DT MAX_DT
----------------------------------------------------------------------------------
1 A 9 January, 12 2012 00:00:00+0000 January, 16 2012 00:00:00+0000
1 A 10 January, 10 2012 00:00:00+0000 January, 11 2012 00:00:00+0000
1 A 10 January, 17 2012 00:00:00+0000 January, 18 2012 00:00:00+0000
我尝试了不同的方法来查询这个,但我无法提供有效的查询。