PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

Practice a data science SQL interview problem that calculates each advertiser's seven-day Shop ad spend share after applying a total-spend threshold. The walkthrough covers conditional aggregation, HAVING filters, safe division, duplicate checks, and validation at the advertiser-ad-day grain.

  • medium
  • Meta
  • Data Manipulation (SQL/Python)
  • Data Scientist

Compute Each Advertiser's Share of Shop Ad Spend

Company: Meta

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Onsite

# Compute Each Advertiser's Share of Shop Ad Spend You have the following daily advertising table: ```text ads_detail( advertiser_id, ad_id, ad_type, ad_objective, ad_spend, ds ) ``` Write SQL that returns, for every advertiser with at least $10,000 in total ad spend during the seven-day window ending on `:as_of_date`, the fraction of that spend attributable to ads whose `ad_type = 'Shop'`. Treat the window as inclusive: `:as_of_date - 6 days` through `:as_of_date`. Return the advertiser, total spend, Shop spend, and Shop spend share. State how you would handle null or duplicated source rows. ### Clarifying Questions to Ask - Is `ad_spend` already aggregated to one row per ad and day? - Should refunds or negative spend be included? - Is `ad_type` case-sensitive, and can it be null? - Should the $10,000 threshold include or exclude advertisers exactly at the boundary? ### What a Strong Answer Covers - Correct conditional aggregation over one consistent seven-day window - Filtering advertisers after aggregation with `HAVING` - Decimal division and safe handling of a zero denominator - Explicit assumptions about table grain, duplicates, nulls, and negative spend - A result that is easy to validate against component totals ### Follow-up Questions 1. How would the query change if ad type can change during the week? 2. How would you test that duplicate ingestion did not inflate spend? 3. How would you compare the distribution of Shop share across advertiser segments? 4. Which indexes or partitions would matter on a very large daily table?

Quick Answer: Practice a data science SQL interview problem that calculates each advertiser's seven-day Shop ad spend share after applying a total-spend threshold. The walkthrough covers conditional aggregation, HAVING filters, safe division, duplicate checks, and validation at the advertiser-ad-day grain.

Last updated: Jul 24, 2026

Loading coding console...

PracHub

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

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.

Related Coding Questions

  • Calculate Daily Survey Response Rates by Country - Meta (medium)
  • Compare Survey Satisfaction for New and Established Users - Meta (medium)
  • Find A Low-Quality Annotator From Label Data - Meta (hard)
  • Analyze Thirty-Day Ad Performance with SQL - Meta (medium)