문제 1. Teams Power Users
Write a query to identify the top 2 Power Users who sent the highest number of messages on Microsoft Teams in August 2022. Display the IDs of these 2 users along with the total number of messages they sent. Output the results in descending order based on the count of the messages.
Assumption:
No two users have sent the same number of messages in August 2022.
https://datalemur.com/questions/teams-power-users
Microsoft SQL Interview Question | DataLemur
Microsoft SQL Interview Question: Write a query to retrieve the top 2 Power Users who sent the highest number of messages.
datalemur.com
💡 문제 풀이
`내 풀이`
소요 시간 03:10
SELECT sender_id,
COUNT(message_id) AS message_count
FROM messages
WHERE EXTRACT (MONTH FROM sent_date) = 8 AND EXTRACT (YEAR FROM sent_date) = 2022
GROUP BY sender_id
ORDER BY message_count desc
LIMIT 2;
💯결과