← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

SQL round at Meta for a Data Scientist role. One question, pretty focused on ad analytics, joins, and window functions. Nothing too wild but the conversion rate edge case tripped me up a bit.

Questions Asked (1)

Q1

Given tables for ads, impressions, and conversions, write SQL to return total impressions, total conversions, conversion rate, and total revenue per ad for the past 30 days. Then extend it to rank ads by conversion rate and pull the top 10.

Product Analytics & MetricsData Modeling
Author's notes

The join chain was fine, impression to conversion is a left join and you group by ad_id, standard stuff.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and assumptions (e.g., date ranges, join keys, revenue definition). Then write a base query that aggregates impressions, conversions, and revenue per ad over the last 30 days, and finally extend it with a window function to rank ads by conversion rate and filter the top 10.

Pro tip: Always handle divide-by-zero when computing conversion rate (e.g., use NULLIF or CASE) and explicitly state that you're using a window function for ranking to avoid aggregation pitfalls.

1. Clarify schema and assumptions

Ask about table structures, join keys, date column, and how revenue is calculated. Confirm that 'past 30 days' means a rolling window from today.

2. Aggregate metrics per ad

Write a query that joins ads, impressions, and conversions, filters for the last 30 days, and groups by ad to compute total impressions, total conversions, conversion rate, and total revenue.

3. Compute conversion rate safely

Use NULLIF or CASE to avoid division by zero when calculating conversion rate (conversions / impressions).

4. Rank ads by conversion rate

Extend the query with a window function (e.g., RANK() or DENSE_RANK()) over the conversion rate in descending order.

5. Filter top 10 and finalize

Wrap the ranked query in a subquery or CTE and filter for rank <= 10, ordering by rank.

Key Points to Mention

  • Use of LEFT JOIN to include ads with zero impressions or conversions
  • Date filtering with a rolling 30-day window (e.g., WHERE date >= CURRENT_DATE - INTERVAL '30 days')
  • Handling division by zero in conversion rate calculation
  • Using window functions (RANK, DENSE_RANK, ROW_NUMBER) for ranking
  • Considering ties in conversion rate and how ranking functions differ
  • Performance considerations: indexing on date and ad_id, and avoiding unnecessary subqueries

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