← All tracks

SQL

Windows, grain, and the query you can defend on a whiteboard

21 questions with hidden solutions

Drill this stack →

  1. Q1StripeSquareShopifySQLhard

    Deduplicate to the latest customer row. Why not filter the window in WHERE?

  2. Q2NetflixSpotifyAirbnbSQLeasy

    Sessionize click events with a 30-minute inactivity gap.

  3. Q3AmazonWalmartInstacartSQLeasy

    Write top-3 orders per country. What breaks if you use RANK() instead of ROW_NUMBER()?

  4. Q4Capital OneJPMorganPayPalSQLmedium

    A join exploded revenue. How do you find the grain mismatch in five minutes?

  5. Q5MetaUberDoorDashSQLmedium

    Running total of daily revenue. Why is SUM(SUM(amount)) OVER (...) valid?

  6. Q6GoogleSnowflakeDatabricksSQLhard

    NULL = NULL is unknown. How does that bite a MERGE or an anti-join?

  7. Q7LinkedInMicrosoftOracleSQLhard

    When do you use a covering index / clustering key versus rewriting the query?

  8. Q8SnowflakeGoogleDatabricksSQLmedium

    QUALIFY vs a CTE for window filters — when do you use each?

  9. Q9GoogleSnowflakeAmazonSQLmedium

    A query is correct but scans last year. How do you prove partition pruning?

  10. Q10Capital OnePayPalStripeSQLeasy

    EXISTS vs IN for an anti-join. Which do you write first?

  11. Q11MetaSnapNetflixSQLmedium

    You need a 7-day rolling unique users. What breaks if you use COUNT DISTINCT in a window carelessly?

  12. Q12StripeShopifySquareSQLmedium

    You need “customers who ordered in January and never in February.” Write the shape, not the dialect.

  13. Q13AirbnbUberDoorDashSQLmedium

    A date spine is missing Sundays. What breaks in a 7-day rolling metric?

  14. Q14Capital OneBloombergTwo SigmaSQLhard

    PERCENTILE_CONT vs PERCENTILE_DISC. When does a hiring manager care?

  15. Q15MetaNetflixSpotifySQLmedium

    You grouped by DATE_TRUNC(week, ts) and compared to last week. Why are week 1 and week 53 lying?

  16. Q16GoogleAmazonMicrosoftSQLhard

    EXPLAIN says Hash Join. When do you want Nested Loop instead?

  17. Q17WalmartTargetInstacartSQLeasy

    A UNION ALL of 12 monthly tables is slower than one partitioned table. Why did someone still union?

  18. Q18PayPalAdyenStripeSQLmedium

    LAG(amount, 1) IGNORE NULLS vs the default. Give a revenue example.

  19. 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.

  20. Q20BloombergJPMorganGoldman SachsSQLeasy

    CROSS JOIN a 10-row parameter table to a 10M-row fact. When is that correct?

  21. Q21SnowflakeDatabricksGitLabSQLeasy

    FILTER (WHERE status = 'paid') on an aggregate vs a CASE. Why mention it?

Search DataLane

↑↓ navigate↵ openesc close