Write a query to obtain a histogram of tweets posted per user in 2022. Output the tweet…
- User
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.
Dataset: CREATE TABLE tweets (tweet_id INTEGER, user_id INTEGER, msg VARCHAR(255), tweet_date TIMESTAMP); INSERT INTO tweets (tweet_id, user_id, msg, tweet_date) VALUES (214252, 111, 'Am considering taking Tesla private at $420. Funding secured.', '2021-12-30 00:00:00'), (739252, 111, 'Despite the constant negative press covfefe', '2022-01-01 00:00:00'), (846402, 111, 'Following @NickSinghTech on Twitter changed my life!', '2022-02-14 00:00:00'), (241425, 254, 'If the salary is so competitive why wont you tell me what it is?', '2022-03-01 00:00:00'), (231574, 148, 'I no longer have a manager. I cant be managed', '2022-03-23 00:00:00');
- Assistant
To create a histogram of tweets posted per user in 2022, you can use a Common Table Expression (CTE) to first calculate the number of tweets each user posted during that year. Then, aggregate these counts to determine how many users fall into each tweet count bucket.
Here's the SQL query to achieve this:
sql