• 牛客SQL题解-汇总各个部门当前员工的title类型的分配数目


    题目描述

    有一个部门表departments简况如下:
     
    有一个,部门员工关系表dept_emp简况如下:
     
     
    有一个职称表titles简况如下:
     
     
    汇总各个部门当前员工的title类型的分配数目,即结果给出部门编号dept_no、dept_name、其部门下所有的员工的title以及该类型title对应的数目count,结果按照dept_no升序排序
     

    答案详解

    解法一

    select dept_emp.dept_no,dept_name,titles.title,count(titles.title)
    from dept_emp,titles,departments
    where dept_emp.dept_no=departments.dept_no
    and dept_emp.emp_no=titles.emp_no
    and titles.to_date='9999-01-01'
    and dept_emp.to_date='9999-01-01'
    group by dept_emp.dept_no,titles.title
    order by dept_emp.dept_no asc
    

    解法二

    select dept_emp.dept_no,dept_name,titles.title,count(titles.title)
    from dept_emp join departments 
    on dept_emp.dept_no=departments.dept_no and dept_emp.to_date='9999-01-01'
    join titles
    on  dept_emp.emp_no=titles.emp_no and titles.to_date='9999-01-01'
    group by dept_emp.dept_no,titles.title
    order by dept_emp.dept_no asc
    

      

  • 相关阅读:
    关于locals()、globals()以及作用域的一些感悟
    Python中创建对象的方法
    Python之__loader__
    tag上、push上和pull 取Docker 映像
    制作Docker镜像
    在Docker Hub上查找可用的Image映像
    window下安装mysql
    linux下安装python3
    yun、apt、wget的区别
    红帽7 Squid部署代理服务
  • 原文地址:https://www.cnblogs.com/Bluebells/p/14516782.html
Copyright © 2020-2023  润新知