User Interaction

ASKED IN INTERVIEW
4pts
Meta

Problem Statement

Meta content creators need a daily summary of how their posts are performing. Interactions are defined as the sum of likes and comments.

Write an SQL query to find the total number of interactions for each post for every day that an interaction occurred.

Rules:

  • An interaction is either a "Like" or a "Comment".
  • Output columns: post_id, interaction_day, total_interactions.
  • Only include posts and days where at least one interaction happened.
  • Results must be sorted by interaction_day in ascending order, then post_id in ascending order.
Tests your understanding of
Union, Aggregation and Join

Input Tables

Posts
post_id(INTEGER)creator_id(INTEGER)content(VARCHAR)
1101Hello World
2102Travel Vlog
3103Cooking Tips
4104SQL Tutorial
5105Funny Meme
6106Tech News
Likes
like_id(INTEGER)post_id(INTEGER)user_id(INTEGER)created_at(TIMESTAMP)
112012026-02-10 10:00:00
212022026-02-10 11:00:00
322012026-02-10 12:00:00
412032026-02-11 09:00:00
Comments
comment_id(INTEGER)post_id(INTEGER)user_id(INTEGER)created_at(TIMESTAMP)
112042026-02-10 10:30:00
222052026-02-11 14:00:00

Expected Output

post_id(INTEGER)interaction_day(DATE)total_interactions(INTEGER)
12026-02-103
22026-02-101
12026-02-111
22026-02-111

Tags

MediumASKED IN INTERVIEWUnionAggregationJoin
10-15 min
74%

Hints