Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Join and Aggregate by Day

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Join and Aggregate by Day. Start with the requirements and the three tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Yahoo Mail analytics needs a daily report for active US users during January 1 through January 3, 2025. Write a PostgreSQL query that joins the user, message-event, and ad-click tables without double-counting metrics.

Requirements

  1. Return one row per day with at least one qualifying message event.
  2. Count sent messages and distinct active users with qualifying Yahoo Mail events.
  3. Include ad-click counts and revenue for the same active US users, returning zero when no clicks exist.
  4. Sort the output chronologically.

Schema

yahoo_mail_users
ColumnTypeDescription
user_idPKINTYahoo Mail user identifier
email_addressVARCHAR(255)Yahoo Mail address
account_statusVARCHAR(20)Current account state
country_codeVARCHAR(2)ISO country code
yahoo_mail_events
ColumnTypeDescription
event_idPKINTMail event identifier
user_idINTReferenced Yahoo Mail user
event_typeVARCHAR(20)Type of mail event
occurred_atTIMESTAMPTZUTC event timestamp
yahoo_mail_ad_clicks
ColumnTypeDescription
click_idPKINTAd-click identifier
user_idINTReferenced Yahoo Mail user
clicked_atTIMESTAMPTZUTC click timestamp
revenueNUMERIC(8,2)Revenue attributed to the click
placementVARCHAR(30)Yahoo Mail ad placement
Tablesyahoo_mail_usersyahoo_mail_eventsyahoo_mail_ad_clicks
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results