sql - Oracle 12c - 过滤具有多个值的记录
问题描述
我有 2 列:
DEPT_ID 号;DEPT_SUB_ID varchar2(5);
我想找到所有的 DEPT_ID 都有一个以上的 DEPT_SUB_ID 唯一值。
如何才能做到这一点?
解决方案
我会使用:
select dept_id
from x
group by dept_id
having min(dept_sub_id) <> max(dept_sub_id);
在许多情况下,两个简单的聚合(例如min()
or max()
)比 a 具有更好的性能count(distinct)
。
推荐阅读
- pandas - Pandas 中的大分类值
- java - DeferredDocumentImpl 上的 XPath 需要很长时间来评估
- redis - Redisson 中的各种锁实现提供了哪些保证?
- python - 如何在其他模块中导入或使用内置模块名称时隐藏它
- sql-server - 安装后更改sql server的默认数据目录
- html - Mp4 视频在 IE11 中不起作用
- java - Java 编码 - 创建答案变量的多个变量
- maven - 为了创建可扩展的项目,声明 MAVEN 依赖项的正确/最佳方式是什么?
- php - 无法使用 curl_multi 访问字母主机
- grpc - Java中的gRPC - 如何接收文件内容作为响应