zoukankan      html  css  js  c++  java
  • 牛客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
    

      

  • 相关阅读:
    继续学习AJAX
    最近在看AJAX
    selenium学习模拟键盘按键操作
    二十三。克隆
    二十五。继承
    十八。类的属性
    二十一。第四章综合例题
    二十四。继承
    十七。对JAVA中堆和栈的细致了解
    十六。方法调用以及传参
  • 原文地址:https://www.cnblogs.com/Bluebells/p/14516782.html
Copyright © 2011-2022 走看看