18 关于查询结果集的去重?

18 关于查询结果集的去重?
    select distinct job from emp; // distinct 关键字 去除重复记录。
        +-----------+
        | job       |
        +-----------+
        | CLERK     |
        | SALESMAN  |
        | MANAGER   |
        | ANALYST   |
        | PRESIDENT |
        +-----------+
 
    select ename,distinct job from emp;
    这条语句是错误的。
    记住:distinct只能出现在所有字段的最前面
    
    select distinct deptno,job from emp;
        +--------+-----------+
        | deptno | job       |
        +--------+-----------+
        |     20 | CLERK     |
        |     30 | SALESMAN  |
        |     20 | MANAGER   |
        |     30 | MANAGER   |
        |     10 | MANAGER   |
        |     20 | ANALYST   |
        |     10 | PRESIDENT |
        |     30 | CLERK     |
        |     10 | CLERK     |
        +--------+-----------+
    
案例:统计岗位的数量?
    select count(distinct job) from emp;
        +---------------------+
        | count(distinct job) |
        +---------------------+
        |                   5 |
        +---------------------+
原文地址:https://www.cnblogs.com/xlwu/p/13639583.html