如何使用where not in



我有这个表

<1>
客户 产品 计数
A 123
A 234 0
A 345 0
B 456
C 567

这里有一个选项。

样本数据:

SQL> with test (customer, product, cnt) as
2    (select 'A', 123, 1 from dual union all
3     select 'A', 234, 0 from dual union all
4     select 'A', 345, 0 from dual union all
5     select 'B', 456, 1 from dual union all
6     select 'C', 567, 1 from dual
7    )

查询:

8  select customer
9  from test
10  group by customer
11  having min(cnt) > 0;
CUSTOMER
----------
B
C
SQL>

最新更新