LeetCode 1076題
1谤牡、先找到最大的數(shù)是多少么库,再分組篩選數(shù)量=最大的項目id
SELECT project_id
FROM Project
GROUP BY project_id
HAVING COUNT(*) = (
SELECT COUNT(*) #找到最大的數(shù)字
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拢切、窗口函數(shù)
(注意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