我有一个包含以下内容的表:
批次 | |
---|---|
1 | 250 |
1 | -250 |
1 | 250 |
1 | 100 |
2 | 50 |
3 | 100 |
3 | 100 |
看起来像group by
&having
:
样本数据:
SQL> with test (batch, amount) as
2 (select 1, 250 from dual union all
3 select 1, -250 from dual union all
4 select 1, 250 from dual union all
5 select 1, 100 from dual union all
6 select 2, 50 from dual union all
7 select 3, 100 from dual union all
8 select 3, 100 from dual
9 )
查询:
10 select batch
11 from test
12 group by batch, abs(amount)
13 having count(*) > 2;
BATCH
----------
1
SQL>