代码拉取完成,页面将自动刷新
# $1731. 每位经理的下属员工数量
# https://leetcode-cn.com/problems/the-number-of-employees-which-report-to-each-employee/
# SQL架构
Create table If Not Exists Employees(employee_id int, name varchar(20), reports_to int, age int);
Truncate table Employees;
insert into Employees (employee_id, name, reports_to, age) values ('9', 'Hercy', null, '43');
insert into Employees (employee_id, name, reports_to, age) values ('6', 'Alice', '9', '41');
insert into Employees (employee_id, name, reports_to, age) values ('4', 'Bob', '9', '36');
insert into Employees (employee_id, name, reports_to, age) values ('2', 'Winston', null, '37');
# Write your MySQL query statement below
select
e2.employee_id,
e2.name,
count(*) as reports_count,
round(avg(e1.age)) as average_age
from
Employees e1
join Employees e2 on e1.reports_to = e2.employee_id
group by
e2.employee_id,
# sql_mode=only_full_group_by
e2.name
order by
e2.employee_id;
# clean-up
drop table Employees;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。