PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Data Manipulation (SQL/Python)/TikTok

Compute CTR drop with exclusions

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to compute time-windowed click-through rates using SQL aggregations, joins, filters and data-cleaning (excluding suspicious ads) while handling edge cases such as missing days, minimum-impression thresholds, division-by-zero, and integer-division pitfalls.

  • Medium
  • TikTok
  • Data Manipulation (SQL/Python)
  • Data Scientist

Compute CTR drop with exclusions

Company: TikTok

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: Medium

Interview Round: Onsite

Assume today = 2025-09-01. Using ad delivery logs, find advertisers whose CTR in the last 7 days (2025-08-25 to 2025-08-31) dropped by at least 20% relative to the previous 7 days (2025-08-18 to 2025-08-24), after excluding suspicious ads. Return advertiser_id, last7_ctr, prev7_ctr, rel_drop (as a positive fraction), ordered by rel_drop DESC. Enforce that both windows have >= 10,000 impressions per advertiser after exclusions. Treat missing days as 0, guard against division-by-zero and integer division. Schema and small samples: Table: advertisers(advertiser_id INT, name TEXT, vertical TEXT) +---------------+----------+-----------+ | advertiser_id | name | vertical | +---------------+----------+-----------+ | 101 | Acme Co | Gaming | | 102 | Beta LLC | Ecommerce | +---------------+----------+-----------+ Table: ad_events(date DATE, advertiser_id INT, ad_id INT, impressions INT, clicks INT, spend_cents INT) +------------+---------------+-------+-------------+--------+-------------+ | date | advertiser_id | ad_id | impressions | clicks | spend_cents | +------------+---------------+-------+-------------+--------+-------------+ | 2025-08-19 | 101 | 9001 | 5000 | 250 | 120000 | | 2025-08-20 | 101 | 9001 | 5500 | 220 | 118000 | | 2025-08-23 | 101 | 9001 | 4500 | 200 | 100000 | | 2025-08-26 | 101 | 9001 | 7000 | 210 | 130000 | | 2025-08-27 | 101 | 9002 | 5000 | 50 | 40000 | | 2025-08-22 | 102 | 9100 | 14000 | 700 | 280000 | | 2025-08-29 | 102 | 9100 | 15000 | 600 | 300000 | | 2025-08-30 | 102 | 9101 | 8000 | 240 | 160000 | +------------+---------------+-------+-------------+--------+-------------+ Table: suspicious_ads(ad_id INT) +-------+ | ad_id | +-------+ | 9002 | +-------+ Write a single SQL query (ANSI SQL preferred) that produces the required output.

Quick Answer: This question evaluates a candidate's ability to compute time-windowed click-through rates using SQL aggregations, joins, filters and data-cleaning (excluding suspicious ads) while handling edge cases such as missing days, minimum-impression thresholds, division-by-zero, and integer-division pitfalls.

Related Interview Questions

  • Find high-value crypto users and top-CTR product - TikTok (easy)
  • Write monthly customer and sales SQL queries - TikTok (easy)
  • Find top-paid employee per department - TikTok (easy)
  • Count buggy vs non-buggy by employer - TikTok (Medium)
  • Select max-discount product per category - TikTok (Medium)
TikTok logo
TikTok
Oct 13, 2025, 9:49 PM
Data Scientist
Onsite
Data Manipulation (SQL/Python)
3
0

Assume today = 2025-09-01. Using ad delivery logs, find advertisers whose CTR in the last 7 days (2025-08-25 to 2025-08-31) dropped by at least 20% relative to the previous 7 days (2025-08-18 to 2025-08-24), after excluding suspicious ads. Return advertiser_id, last7_ctr, prev7_ctr, rel_drop (as a positive fraction), ordered by rel_drop DESC. Enforce that both windows have >= 10,000 impressions per advertiser after exclusions. Treat missing days as 0, guard against division-by-zero and integer division. Schema and small samples:

Table: advertisers(advertiser_id INT, name TEXT, vertical TEXT) +---------------+----------+-----------+ | advertiser_id | name | vertical | +---------------+----------+-----------+ | 101 | Acme Co | Gaming | | 102 | Beta LLC | Ecommerce | +---------------+----------+-----------+

Table: ad_events(date DATE, advertiser_id INT, ad_id INT, impressions INT, clicks INT, spend_cents INT) +------------+---------------+-------+-------------+--------+-------------+ | date | advertiser_id | ad_id | impressions | clicks | spend_cents | +------------+---------------+-------+-------------+--------+-------------+ | 2025-08-19 | 101 | 9001 | 5000 | 250 | 120000 | | 2025-08-20 | 101 | 9001 | 5500 | 220 | 118000 | | 2025-08-23 | 101 | 9001 | 4500 | 200 | 100000 | | 2025-08-26 | 101 | 9001 | 7000 | 210 | 130000 | | 2025-08-27 | 101 | 9002 | 5000 | 50 | 40000 | | 2025-08-22 | 102 | 9100 | 14000 | 700 | 280000 | | 2025-08-29 | 102 | 9100 | 15000 | 600 | 300000 | | 2025-08-30 | 102 | 9101 | 8000 | 240 | 160000 | +------------+---------------+-------+-------------+--------+-------------+

Table: suspicious_ads(ad_id INT) +-------+ | ad_id | +-------+ | 9002 | +-------+

Write a single SQL query (ANSI SQL preferred) that produces the required output.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Data Manipulation (SQL/Python)•More TikTok•More Data Scientist•TikTok Data Scientist•TikTok Data Manipulation (SQL/Python)•Data Scientist Data Manipulation (SQL/Python)
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.