SQL:返回由另一列分组的列中包含两个以上相同绝对值的所有行

  • 本文关键字:包含两 绝对值 返回 一列 SQL sql oracle
  • 更新时间 :
  • 英文 :


我有一个包含以下内容的表:

金额
批次
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>

相关内容

最新更新