Daily Click-Through Rate per Campaign Including Zero-Click Days

Last updated: November 29, 2026

Quick Overview

Given an impressions table and a clicks table keyed by impression id, write SQL that returns each campaign's impressions, clicks and CTR for every day it served, showing 0 clicks rather than dropping days with no clicks.

StackAdapt
Data Manipulation (SQL/Python)
Data Engineer
StackAdapt
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given an impressions table and a clicks table keyed by impression id, write SQL that returns each campaign's impressions, clicks and CTR for every day it served, showing 0 clicks rather than dropping days with no clicks.

StackAdapt's reporting dashboards show agencies per-day delivery for each campaign, and a missing row reads as an outage to a customer. The screen checks join direction, duplicate click handling and safe division.

What the Interviewer Expects
  • Starts from impressions and LEFT JOINs clicks
  • Deduplicates repeated clicks on one impression
  • Groups by campaign and calendar day in a stated time zone
  • Avoids integer division and divide-by-zero
  • Explains how they would verify totals
Key Topics to Cover
LEFT JOIN
Aggregation
Deduplication
Time zones
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • Clicks can arrive up to 7 days after the impression; which date should a click count toward?
  • How would you show days where the campaign was live but served nothing?
  • How would you make this incremental over billions of rows a day?
  • How would you filter out invalid or bot clicks?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

impressions(impression_id, campaign_id, served_at) one row per impression, served_at stored in UTC. clicks(click_id, impression_id, clicked_at) can hold several rows per impression if a user dou...

Approach

Collapse clicks to one row per impression first, so the join cannot multiply impression counts. LEFT JOIN that onto impressions so impressions without clicks survive. Group by campaign and local day, ...


Submit Your Answer
Markdown supported

Related Questions