前五道題: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