-
Notifications
You must be signed in to change notification settings - Fork 4
LeetCode SQL 50 #22
Answered
by
iamAntimPal
IamShiwangi
asked this question in
Q&A
LeetCode SQL 50
#22
-
Beta Was this translation helpful? Give feedback.
All reactions
Answered by
iamAntimPal
Mar 21, 2025
# Write your MySQL query statement below
WITH
S AS (
SELECT 'Low Salary' AS category
UNION
SELECT 'Average Salary'
UNION
SELECT 'High Salary'
),
T AS (
SELECT
CASE
WHEN income < 20000 THEN "Low Salary"
WHEN income > 50000 THEN 'High Salary'
ELSE 'Average Salary'
END AS category,
COUNT(1) AS accounts_count
FROM Accounts
GROUP BY 1
)
SELECT category, IFNULL(accounts_count, 0) AS accounts_count
FROM
S
LEFT JOIN T USING (category);
For Explanation got to 1907. Count Salary Categories
Replies: 2 comments 1 reply
-
# Write your MySQL query statement below
WITH
S AS (
SELECT 'Low Salary' AS category
UNION
SELECT 'Average Salary'
UNION
SELECT 'High Salary'
),
T AS (
SELECT
CASE
WHEN income < 20000 THEN "Low Salary"
WHEN income > 50000 THEN 'High Salary'
ELSE 'Average Salary'
END AS category,
COUNT(1) AS accounts_count
FROM Accounts
GROUP BY 1
)
SELECT category, IFNULL(accounts_count, 0) AS accounts_count
FROM
S
LEFT JOIN T USING (category);
For Explanation got to 1907. Count Salary Categories
Beta Was this translation helpful? Give feedback.
All reactions
1 reply
-
Thank you so much sir
Beta Was this translation helpful? Give feedback.
All reactions
Answer selected by
IamShiwangi
-
i understand all of that
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment