Deduplicate Retried Pangle Ad Logs Before Computing Daily Campaign CTR

Last updated: November 29, 2026

Quick Overview

Given an impressions table and a clicks table where client retries create duplicate rows in both, write SQL that returns daily click-through rate per campaign, counting each impression and each clicked impression once.

ByteDance
Data Manipulation (SQL/Python)
Data Scientist
ByteDance
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given an impressions table and a clicks table where client retries create duplicate rows in both, write SQL that returns daily click-through rate per campaign, counting each impression and each clicked impression once.

A warm-up SQL question in a ByteDance ads data science screen, framed around Pangle or TikTok ads logging where SDK retries and at-least-once delivery produce duplicate events. The interviewer checks whether you define the grain before aggregating and avoid the join fan-out that inflates CTR.

What the Interviewer Expects
  • Asks what uniquely identifies an impression and a click before writing SQL
  • Deduplicates both tables to the impression grain before joining
  • Uses a LEFT JOIN so campaigns with zero clicks still appear
  • Explains why COUNT(*) after a raw join would overstate both numerator and denominator
  • Handles orphan clicks and clicks timestamped before their impression
Key Topics to Cover
deduplication
LEFT JOIN
grain of a table
CTR
ads logging
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
  • How would you attribute a click to the day of the impression versus the day of the click, and which does the ads team want?
  • What if impression_id can be reused across campaigns after a bug?
  • How would you restrict clicks to a 24 hour attribution window?
  • How would you monitor the duplicate rate itself as a data quality metric?
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

Tables: ad_impressions(impression_id, campaign_id, user_id, ts) and ad_clicks(click_id, impression_id, ts). I confirm that impression_id is the true key and that retries resend the same id with ...

Approach
  1. Collapse impressions to one row per impression_id, keeping the earliest timestamp.
  2. Collapse clicks to the set of distinct impression ids that were clicked, dropping clicks whose impression is ...

Submit Your Answer
Markdown supported