← All tracks
SQL
Windows, grain, and the query you can defend on a whiteboard
21 questions with hidden solutions
Drill this stack →- Q1StripeSquareShopifySQLhard
Deduplicate to the latest customer row. Why not filter the window in WHERE?
- Q2NetflixSpotifyAirbnbSQLeasy
Sessionize click events with a 30-minute inactivity gap.
- Q3AmazonWalmartInstacartSQLeasy
Write top-3 orders per country. What breaks if you use RANK() instead of ROW_NUMBER()?
- Q4Capital OneJPMorganPayPalSQLmedium
A join exploded revenue. How do you find the grain mismatch in five minutes?
- Q5MetaUberDoorDashSQLmedium
Running total of daily revenue. Why is SUM(SUM(amount)) OVER (...) valid?
- Q6GoogleSnowflakeDatabricksSQLhard
NULL = NULL is unknown. How does that bite a MERGE or an anti-join?
- Q7LinkedInMicrosoftOracleSQLhard
When do you use a covering index / clustering key versus rewriting the query?
- Q8SnowflakeGoogleDatabricksSQLmedium
QUALIFY vs a CTE for window filters — when do you use each?
- Q9GoogleSnowflakeAmazonSQLmedium
A query is correct but scans last year. How do you prove partition pruning?
- Q10Capital OnePayPalStripeSQLeasy
EXISTS vs IN for an anti-join. Which do you write first?
- Q11MetaSnapNetflixSQLmedium
You need a 7-day rolling unique users. What breaks if you use COUNT DISTINCT in a window carelessly?
- Q12StripeShopifySquareSQLmedium
You need “customers who ordered in January and never in February.” Write the shape, not the dialect.
- Q13AirbnbUberDoorDashSQLmedium
A date spine is missing Sundays. What breaks in a 7-day rolling metric?
- Q14Capital OneBloombergTwo SigmaSQLhard
PERCENTILE_CONT vs PERCENTILE_DISC. When does a hiring manager care?
- Q15MetaNetflixSpotifySQLmedium
You grouped by DATE_TRUNC(week, ts) and compared to last week. Why are week 1 and week 53 lying?
- Q16GoogleAmazonMicrosoftSQLhard
EXPLAIN says Hash Join. When do you want Nested Loop instead?
- Q17WalmartTargetInstacartSQLeasy
A UNION ALL of 12 monthly tables is slower than one partitioned table. Why did someone still union?
- Q18PayPalAdyenStripeSQLmedium
LAG(amount, 1) IGNORE NULLS vs the default. Give a revenue example.
- Q19MetaSnapPinterestSQLhard
You must count distinct users in a 30-day window every day. Sketch a table design that does not scan 30 days of events nightly.
- Q20BloombergJPMorganGoldman SachsSQLeasy
CROSS JOIN a 10-row parameter table to a 10M-row fact. When is that correct?
- Q21SnowflakeDatabricksGitLabSQLeasy
FILTER (WHERE status = 'paid') on an aggregate vs a CASE. Why mention it?