美文网首页
mysql-distinct去除重复数据

mysql-distinct去除重复数据

作者: ssttIsme | 来源:发表于2020-04-06 16:10 被阅读0次
    select distinct a 
    from ...
    -- 查询字段a 并去除重复数据
    
    select distinct a,b
    from ...
    -- ab组合 去除重复数据
    

    1.部门编号

    USE hr;
    SELECT DISTINCT department_id
    FROM employees
    WHERE department_id IS NOT NULL;
    

    2.工种代码

    USE hr;
    SELECT DISTINCT job_id
    FROM employees ORDER BY job_id;
    

    3.主管id

    USE hr;
    SELECT DISTINCT manager_id
    FROM employees 
    WHERE manager_id IS NOT NULL;
    

    4.部门中的主管id

    USE hr;
    SELECT DISTINCT department_id,manager_id
    FROM employees 
    WHERE department_id IS NOT NULL
    AND manager_id IS NOT NULL
    ORDER BY department_id,manager_id;
    

    相关文章

      网友评论

          本文标题:mysql-distinct去除重复数据

          本文链接:https://www.haomeiwen.com/subject/qgsbphtx.html