当前位置:首页 >> 核电技术聚变聚能设备 >> 【SQL】1731. 每位经理的下属员工数量 ( 新思想:确定左表,依次添加后续字段),瑞星2010

【SQL】1731. 每位经理的下属员工数量 ( 新思想:确定左表,依次添加后续字段),瑞星2010

cpugpu芯片开发光刻机 核电技术聚变聚能设备 2
文件名:【SQL】1731. 每位经理的下属员工数量 ( 新思想:确定左表,依次添加后续字段),瑞星2010 【SQL】1731. 每位经理的下属员工数量 ( 新思想:确定左表,依次添加后续字段)

leetcode题目链接

注意点 确定左表(即,确定result表中的主键),依次添加后续字段。注意:主键可能是一个字段,也可能是多个字段COUNT(DISTINCT()),一般为了防止重复,使用COUNT计数时,一般带着DISTINCT(),不然就跟COUNT(1)、COUNT(常数)一样了。一般,非聚合字段都要group by 写法一:思想:( 确定左表,依次添加后续字段) select a.employee_id, b.name, reports_count, average_agefrom (select reports_to as employee_id, count(distinct(employee_id)) as reports_count, round(AVG(age)) as average_agefrom employeeswhere reports_to is not nullgroup by reports_to) a left join (select employee_id, namefrom employeesgroup by employee_id, name) bon a.employee_id = b.employee_idorder by employee_id asc 写法二:内连接 # 写法二select a.employee_id, a.name, count(distinct(b.employee_id)) as reports_count, round(avg(b.age)) as average_age from employees ainner join employees bon a.employee_id = b.reports_togroup by a.employee_id, a.name# 注意:非聚合字段都要group by
协助本站SEO优化一下,谢谢!
关键词不能为空
同类推荐
«    2025年12月    »
1234567
891011121314
15161718192021
22232425262728
293031
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接