Career Hub/Interview questions/Histogram of Tweets
Twitter logo

Histogram of Tweets

Twitter·easy·SQL

Given a table of tweets, calculate the number of tweets posted per user in 2022, then show how many users posted each tweet count. Output the tweet count bucket and the number of users in that bucket.

Schema

tweets
tweet_idINTEGER
user_idINTEGER
msgVARCHAR
tweet_dateDATETIME

Target output

Target output
tweet_bucketusers_num
110
25
32

What this question tests

Tests two-step aggregation: count tweets per user, then count the users at each tweet count. Histogram questions are a classic analytics-interview warm-up because they prove you can treat one aggregation as the input to another, the pattern behind almost every distribution question that follows.

More SQL interview questions

  • Sending vs Opening Snaps · Snapchat · medium
  • Inactive Traders · Robinhood · easy
  • Vacant Days in 2021 · Airbnb · hard
Querytweets
Cmd+Enterto runLoading...
Output

Loading sample data...