LeetCode 1076题
project
image.png
1、先找到最大的数是多少,再分组筛选数量=最大的项目id
SELECT project_id
FROM Project
GROUP BY project_id
HAVING COUNT(*) = (
SELECT COUNT(*) #找到最大的数字
FROM Project
GROUP BY project_id
ORDER BY COUNT(*) DESC
LIMIT 1
)
2、筛选条件≥ALL(子查询)
SELECT project_id
FROM Project
GROUP BY project_id
HAVING COUNT(*) >= ALL (
SELECT COUNT(*)
FROM Project
GROUP BY project_id
)
3、窗口函数
(注意group by和partition by用法)
SELECT project_id
FROM (
SELECT project_id, rank() OVER(ORDER BY COUNT(employee_id) DESC) rk
FROM Project
GROUP BY project_id
) t
WHERE t.rk=1
网友评论