PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches

Quick Overview

This question evaluates SQL-based data manipulation competency, including multi-table joins, aggregations, time-based bucketing and filtering for CTR calculation, and currency conversion using FX rate lookups within the Data Manipulation (SQL/Python) domain.

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

Write SQL for CTR and revenue

Company: Meta

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

Write SQL for the following two tasks. **Problem 1: CTR during peak vs. non-peak hours** You are given three tables: - `ads(ad_id BIGINT, advertiser_id BIGINT, ad_type STRING, status STRING, created_at TIMESTAMP)` - `impressions(impression_id BIGINT, ad_id BIGINT, user_id BIGINT, impression_ts TIMESTAMP, clicked BOOLEAN)` - `conversions(conversion_id BIGINT, impression_id BIGINT, conversion_ts TIMESTAMP, conversion_value_usd DECIMAL(18,2))` Key relationships: - `ads.ad_id = impressions.ad_id` - `impressions.impression_id = conversions.impression_id` Assume all timestamps are stored in UTC. For the last 30 complete days, compare click-through rate during **peak hours** versus **non-peak hours** for active ads. Define: - peak hours = `18:00:00` to `21:59:59` UTC - non-peak hours = all other times - CTR = `clicks / impressions`, where a click is an impression row with `clicked = TRUE` Return one row per time bucket with these columns: - `time_bucket` (`'peak'` or `'non_peak'`) - `impression_count` - `click_count` - `ctr` **Problem 2: US and global ad revenue with FX conversion** You are given two tables: - `ad_revenue(event_date DATE, ad_id BIGINT, country_code STRING, currency_code STRING, revenue_local DECIMAL(18,2))` - `fx_rates(rate_date DATE, currency_code STRING, usd_per_unit DECIMAL(18,6))` Key relationships: - `ad_revenue.event_date = fx_rates.rate_date` - `ad_revenue.currency_code = fx_rates.currency_code` Assume `usd_per_unit` means 1 unit of local currency equals `usd_per_unit` USD, all dates are UTC calendar dates, and `USD` has a rate of `1.0`. For each date in January 2024, calculate: - US ad revenue in USD, where `country_code = 'US'` - global ad revenue in USD, across all countries Return: - `event_date` - `us_revenue_usd` - `global_revenue_usd`

Quick Answer: This question evaluates SQL-based data manipulation competency, including multi-table joins, aggregations, time-based bucketing and filtering for CTR calculation, and currency conversion using FX rate lookups within the Data Manipulation (SQL/Python) domain.

Last updated: May 7, 2026

Loading coding console...

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.

Related Coding Questions

  • Compute ad impression conversion rates - Meta (medium)
  • Count unconnected posts and reactions - Meta (medium)
  • Count heavy callers in 7 days - Meta (medium)
  • Write SQL for call metrics - Meta (medium)
  • Write SQL for multi-account metrics - Meta (medium)