문제 1. Histogram of Tweets
Assume you're given a table Twitter tweet data, write a query to obtain a histogram of tweets posted per user in 2022. Output the tweet count per user as the bucket and the number of Twitter users who fall into that bucket.
In other words, group the users by the number of tweets they posted in 2022 and count the number of users in each group.
https://datalemur.com/questions/sql-histogram-tweets
Twitter SQL Interview Question | DataLemur
Twitter SQL Interview Question: Write a query to obtain the histogram of tweets posted per user in 2022.
datalemur.com
💡 문제 풀이
`내 풀이`
WITH a AS(
SELECT user_id, COUNT(tweet_id) AS tweet_bucket
FROM tweets
WHERE extract(year from tweet_date) = 2022
GROUP BY user_id
)
SELECT tweet_bucket, COUNT(user_id) AS users_num
FROM a
GROUP BY tweet_bucket;
💯결과