oracle distinct学习

1、distinct作用是去掉重复值。

select distinct ename from emp;

2、但是往往distinct是用来计算不重复记录的条数,而不是用它来返回不重记录的所有值。

distinct可以这样用:

select count(sal), count(distinct deptno) from emp;

3、如果distinct后面跟多个值,sql是怎么进行处理的呢?

select distinct job, sal from emp;

实际上是distinct后面字段的组合,去掉重复值!

PS:group by后跟多个列是先按第一个列分组,在第一个列分组内再按第二个列分组,以此类推。
PS2:order by后跟多个列是先按第一个列排序,在第一个列排序内再按第二个列排序,以此类推。