Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Join and Aggregate by Day
00:00
5 left

Join and Aggregate by Day

MediumSQL · PostgreSQL

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
Interviewer

Your question is Join and Aggregate by Day. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.