管理

oracle中distinct和count函数组合使用

Posted on 2008-12-24 14:31  lzhdim  阅读(3023)  评论(0编辑  收藏  举报

oracle中的distinc关键字和count函数需要经常组合起来使用,例如,如果我们拿到一个仅有员工基本信息的列表,我们希望得到这个公司共有多少个部门。

我们可以这样做:
select count(a.deptno) from (select distinct deptno from scott.emp) a;
但这样做太复杂了,我们可以将discint和count函数用在一起
例如:
select count(distinct deptno) from scott.emp;

二者效果是一样的。

Copyright © 2000-2022 Lzhdim Technology Software All Rights Reserved