首页 > 解决方案 > Oracle 12c - 过滤具有多个值的记录

问题描述

我有 2 列:

DEPT_ID 号;DEPT_SUB_ID varchar2(5);

我想找到所有的 DEPT_ID 都有一个以上的 DEPT_SUB_ID 唯一值。

如何才能做到这一点?

标签: sqloracleoracle12c

解决方案


我会使用:

select dept_id
from x
group by dept_id
having min(dept_sub_id) <> max(dept_sub_id);

在许多情况下,两个简单的聚合(例如min()or max())比 a 具有更好的性能count(distinct)


推荐阅读