PostgreSQL 풀이 | Histogram of Tweets

2025. 3. 7. 15:49·SQL

문제 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;

💯결과

 

 

'SQL' 카테고리의 다른 글
  • PostgreSQL 풀이 | Teams Power Users
  • PostgreSQL 풀이 | Highest-Grossing Items
  • PostgreSQL 풀이 | Data Science Skills
  • PostgreSQL 풀이 | Unfinished Parts
초담
초담
4년차 마케터입니다
  • 초담
    그로스마케터의 기록
    초담
  • 전체
    오늘
    어제
  • 글쓰기 관리
    • 분류 전체보기 (117)
      • Data Analytics Project (3)
      • SQL (55)
      • Python (43)
      • GA4 (0)
      • Tableau (8)
      • 아티클 스터디 (7)
  • 인기 글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.2
초담
PostgreSQL 풀이 | Histogram of Tweets
상단으로

티스토리툴바