LeetCode 高频 SQL 50 题(基础版)之 【连接】部分 · 下
前五道题:LeetCode 高频 SQL 50 题(基础版)之 【连接】部分 · 上
题目:577. 员工奖金
题解:
select r.name,b.bonus from Employee r left join Bonus b on r.empId=b.empId
where b.bonus <1000 or b.bonus is null
题目:1280. 学生们参加各科测试的次数
题解:
select stu.student_id student_id, stu.student_name student_name,sub.subject_name subject_name,
count(ex.student_id) attended_exams
from Students stu
join Subjects sub
left join Examinations ex
on stu.student_id = ex.student_id and sub.subject_name = ex.subject_name
group by stu.student_id ,sub.subject_name
order by stu.student_id ,sub.subject_name
题目:570. 至少有5名直接下属的经理
题解:
select name from Employee
where id in (select managerId from Employeegroup by managerIdhaving count(managerId)>=5
)
题目:1934. 确认率
题解:
select s.user_id user_id, round( ifnull(avg(c.action='confirmed'),0),2) confirmation_rate from Signups s left join Confirmations c
on s.user_id = c.user_id
group by s.user_id