Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Star Schema for Ad Metrics
00:00
5 left

Star Schema for Ad Metrics

MediumSQL · PostgreSQL

Problem

How would you design a star schema for tracking user ad impressions and clicks across different platforms for Reddit?

Assume the schema includes user and platform dimensions plus a daily ad engagement fact table. Write a SQL query that summarizes all platforms, including platforms without activity.

Output

  1. One row per platform with platform_name, unique_users, total_impressions, total_clicks, and ctr_percent
  2. Include platforms with no fact rows, representing their metrics as zero
  3. Sort by total_impressions descending, then platform_id ascending

Schema

dim_platforms
ColumnTypeDescription
platform_idPKINTSurrogate key for an advertising platform
platform_nameVARCHAR(50)Name of the Reddit ad delivery platform
platform_typeVARCHAR(30)Platform classification
dim_users
ColumnTypeDescription
user_idPKINTReddit user identifier
user_nameVARCHAR(80)Anonymized Reddit username
country_codeVARCHAR(2)Two-letter user country code
fact_ad_engagement_daily
ColumnTypeDescription
engagement_idPKINTFact row identifier
user_idINTUser associated with the daily engagement
platform_idINTPlatform associated with the engagement
engagement_dateDATEDate represented by the fact row
impressionsINTNumber of ad impressions
clicksINTNumber of ad clicks
Tablesdim_platformsdim_usersfact_ad_engagement_daily
Interviewer

Your question is Star Schema for Ad Metrics. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.