← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Meta Data Scientist SQL round, focused entirely on ad analytics. Two related questions, both involving the same tables, just different levels of aggregation. Nothing too wild but the CAST thing is easy to forget under pressure.

Questions Asked (2)

Q1

Write SQL to compute the overall click-through rate (clicks divided by impressions) across all ads for the last calendar week.

Product Analytics & MetricsData Modeling
Author's notes

The mechanics are straightforward: filter by event_date, count impressions and clicks separately using conditional aggregation, then divide.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and definitions: what tables contain impressions and clicks, how timestamps are stored, and what 'last calendar week' means (e.g., Monday-Sunday). Then write a SQL query that filters events to the last complete calendar week, aggregates clicks and impressions separately, and computes the ratio. Use a single query with conditional aggregation or subqueries to ensure accurate totals.

Pro tip: Always clarify the definition of 'last calendar week' and whether to include partial weeks. Also, consider edge cases like ads with zero impressions and whether to use SUM(clicks)/SUM(impressions) or AVG(click-through rate per ad) — the former is correct for overall CTR.

1. Clarify requirements and schema

Ask about table structures, column names, and how clicks and impressions are recorded. Confirm the definition of 'last calendar week' (e.g., previous Monday to Sunday) and whether to include only complete weeks.

2. Filter to last calendar week

Use date functions to restrict the data to the last calendar week. For example, in PostgreSQL: WHERE event_date >= date_trunc('week', current_date) - interval '1 week' AND event_date < date_trunc('week', current_date).

3. Aggregate clicks and impressions

Sum clicks and impressions separately across all ads. If clicks and impressions are in the same table with an event type, use conditional aggregation: SUM(CASE WHEN event_type = 'click' THEN 1 ELSE 0 END) AS clicks, SUM(CASE WHEN event_type = 'impression' THEN 1 ELSE 0 END) AS impressions.

4. Compute overall CTR

Divide total clicks by total impressions, ensuring to handle division by zero. Use CAST to float to avoid integer division: CAST(clicks AS FLOAT) / NULLIF(impressions, 0) AS ctr.

5. Present and validate

Show the final SQL query and explain the result. Mention potential pitfalls like timezone differences, data completeness, and whether to include ads with zero impressions.

Key Points to Mention

  • Definition of 'last calendar week' and date filtering logic
  • Handling of clicks and impressions from separate tables or event types
  • Use of conditional aggregation or subqueries for efficient computation
  • Importance of using SUM(clicks)/SUM(impressions) for overall CTR, not average of per-ad CTRs
  • Division by zero handling with NULLIF or CASE
  • Timezone considerations and data completeness for the week

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Now break that CTR down by campaign type. Same time period, but join to the campaigns table and group by campaign_type.

Product Analytics & MetricsData Modeling
Author's notes

Pretty much the same query with a JOIN and a GROUP BY tacked on.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the metric definition and time period, then write a SQL query that joins the click events table to the campaigns table on campaign_id, filters for the same time period, and groups by campaign_type to compute CTR (clicks/impressions) per type. Finally, validate the results and discuss any data quality or interpretation considerations.

Pro tip: Always confirm whether CTR should be computed as total clicks divided by total impressions (weighted) or as an average of per-campaign CTRs (unweighted), as this choice can significantly change the results and reflects analytical rigor.

1. Clarify the metric and scope

Confirm the definition of CTR (clicks/impressions) and the exact time period. Ensure you understand which tables contain clicks, impressions, and campaign metadata.

2. Identify the join key and tables

Determine that the events table (with clicks and impressions) must be joined to the campaigns table on campaign_id. Verify that campaign_type is available in the campaigns table.

3. Write the SQL query

Construct a query that filters events to the same time period, joins to campaigns, groups by campaign_type, and calculates CTR as SUM(clicks)/SUM(impressions). Use appropriate aggregation functions.

4. Validate and interpret results

Check for nulls, duplicate joins, or missing campaign types. Discuss whether the CTR differences are statistically significant and what they imply for campaign performance.

Key Points to Mention

  • Correct join condition: events.campaign_id = campaigns.campaign_id
  • Time period filter applied consistently to both tables (or only to events if campaigns are static)
  • CTR calculation: SUM(clicks) / SUM(impressions) to get weighted average, not AVG(click/impression)
  • Handling of campaigns with zero impressions (avoid division by zero)
  • Grouping by campaign_type and ordering results for readability
  • Potential data quality issues: missing campaign_type, duplicate events, or time zone considerations

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.