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
    

      

  • 相关阅读:
    算法
    算法
    算法
    算法
    mysql使用注意事项
    公共接口限制IP请求次数的一种方式(redis版)
    vue echarts 折线图 饼图 地图
    springboot Redis缓存应用示例
    springboot 响应消息 message简单封装 单例和原型模式
    springboot 请求外部接口方法
  • 原文地址:https://www.cnblogs.com/Bluebells/p/14516782.html
Copyright © 2011-2022 走看看