|
这种反例举得很好。
我的语句也只要改改就可以了,就是复杂了点, 呵呵
测试如下:
SQL> select id,
2 name,
3 to_char(RDateTime, 'yyyymmdd hh24:mi:ss') RDateTime
4 from
5 (select id,
6 name,
7 RDateTime,
8 flag,
9 count(distinct name) over(partition by flag) cnt1,
10 count(name) over(partition by flag) cnt2,
11 count(*) over(partition by flag, name) cnt3
12 from
13 (select id,
14 name,
15 RDateTime,
16 min(id) over(partition by name order by RDateTime range between NUMTODSINTERVAL(2, 'hour') preceding and NUMTODSINTERVAL(2, 'hour') following) flag
17 from t_xyh1))
18 where cnt1 <> cnt2
19 and cnt2 > 1
20 and cnt3 > 1;
ID NAME RDATETIME
---------- ---------------------- -----------------
4 aa 20120101 11:11:11
1 aa 20120101 12:11:11
2 aa 20120101 13:11:11
SQL>
SQL> select id, name, to_char(RDateTime, 'yyyymmdd hh24:mi:ss') RDateTime from t_xyh2;
ID NAME RDATETIME
---------- ---------------------- -----------------
1 aa 20120101 10:00:00
2 bb 20120101 11:11:11
3 cc 20120101 11:50:00
4 cc 20120101 13:00:00
SQL>
SQL> select id,
2 name,
3 to_char(RDateTime, 'yyyymmdd hh24:mi:ss') RDateTime
4 from
5 (select id,
6 name,
7 RDateTime,
8 flag,
9 count(distinct name) over(partition by flag) cnt1,
10 count(name) over(partition by flag) cnt2,
11 count(*) over(partition by flag, name) cnt3
12 from
13 (select id,
14 name,
15 RDateTime,
16 min(id) over(partition by name order by RDateTime range between NUMTODSINTERVAL(2, 'hour') preceding and NUMTODSINTERVAL(2, 'hour') following) flag
17 from t_xyh2))
18 where cnt1 <> cnt2
19 and cnt2 > 1
20 and cnt3 > 1;
ID NAME RDATETIME
---------- ---------------------- -----------------
3 cc 20120101 11:50:00
4 cc 20120101 13:00:00
|
|