[LeetCode/SQL]
📌 1907. Count Salary Categories
풀이
- 급여 범주에 따라 각 범주에 속하는 은행 계좌 수 출력 - "Low Salary," :20000 이하
- "Average Salary," :20000이상 50000 이하
-"High Salary" : 50000 초과
- 만약 해당 범주에 속하는 계좌가 없으면 0을 반환
방법 I
WITH SalaryCategories AS (
SELECT
'Low Salary' AS category,
COUNT(*) AS accounts_count
FROM Accounts
WHERE income < 20000
UNION ALL
SELECT
'Average Salary' AS category,
COUNT(*) AS accounts_count
FROM Accounts
WHERE income BETWEEN 20000 AND 50000
UNION ALL
SELECT
'High Salary' AS category,
COUNT(*) AS accounts_count
FROM Accounts
WHERE income > 50000
)
SELECT
category,
COALESCE(accounts_count, 0) AS accounts_count
FROM SalaryCategories;