1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-1731.test 1010 Bytes
一键复制 编辑 原始数据 按行查看 历史
逸扬 提交于 2022-04-17 19:57 . fix lc-1731.test
# $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;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

搜索帮助