Skip to content
Reliable Data Engineering
Overview

SQL Practice Problems

Every problem is runnable. The schema and solution are executed in SQLite by scripts/build.py, which also generates the expected output, so every answer is verified. Use the web platform to write and auto-check your own queries in the browser.

How to practise: read the problem and schema, write your query, compare with the expected output, then read the explanation and the follow-ups (interviewers almost always ask one).

Learn the patterns first: Window functions · Advanced patterns · Performance & dialects

Easy

#ProblemTopicsAsked at
01Second (Nth) Highest Salaryranking, subquery, dense-rankMeta, Amazon, Microsoft
02Keep the Latest Record per Customerdeduplication, row-number, window-functionsDatabricks, Airbnb, Netflix
03Customers Who Never Orderedanti-join, not-exists, nullsAmazon, Uber, Meta
04Daily Active Users and Stickinessaggregation, count-distinct, self-joinMeta, Snap, Spotify
05Running Total of Revenue per Customerwindow-functions, running-total, framesAmazon, Stripe, Shopify
06Category Share of Revenuewindow-functions, aggregation, percent-of-totalAmazon, Walmart, Instacart
07Month-over-Month and Year-over-Year Growthlag, window-functions, time-seriesGoogle, Netflix, Airbnb
08First Purchase per Customerrow-number, min-by, window-functionsDoorDash, Uber Eats, Shopify
09Days Warmer Than the Previous Daylag, self-join, datesAmazon, Adobe
10Histogram of Orders per Customeraggregation, left-join, histogramMeta, Twitter/X, Etsy

Medium

#ProblemTopicsAsked at
117-Day Moving Average of Revenuemoving-average, window-functions, framesAmazon, Meta, Google, Netflix
12Moving Average with Missing Daysmoving-average, range-frame, date-spineUber, Airbnb, Stripe
13Top 3 Salaries per Departmentranking, dense-rank, top-nAmazon, Meta, Microsoft, Apple
14Users with 3+ Consecutive Login Daysgaps-and-islands, row-number, datesMeta, Google, LinkedIn, Uber
15Sessionize Clickstream Eventssessionization, lag, running-sumGoogle, Amazon, Spotify, Pinterest
16Ordered Funnel Conversionfunnel, conditional-aggregation, product-analyticsMeta, Amazon, Booking.com, Shopify
17Month-over-Month User Retentionretention, self-join, product-analyticsMeta, Spotify, Netflix, Duolingo
18Cohort Retention Matrixcohorts, retention, window-functionsAirbnb, Uber, Robinhood, Duolingo
19Median Order Value per Countrymedian, percentiles, window-functionsGoogle, Airbnb, Lyft
20New Users per Day and Cumulative User Countrunning-total, first-seen, date-spineMeta, Snap, Discord
21Users Who Bought A and Then B Within 7 Daysself-join, sequencing, time-boundsAmazon, Instacart, Walmart
22Pivot Monthly Revenue into Columnspivot, conditional-aggregation, rollupMicrosoft, Salesforce, Oracle
23Friend Request Acceptance Rate by Dayratios, left-join, running-totalMeta, LinkedIn
24Apply CDC Events to Get the Current Table Statecdc, deduplication, merge-logicDatabricks, Confluent, Netflix, Stripe
25Average Days Between Purchaseslag, time-between-events, aggregationAmazon, Starbucks, Chewy
26Last-Touch Marketing Attributionattribution, as-of-join, row-numberGoogle, Meta, TikTok, Uber
27Rolling 3-Month Revenue per Customerrange-frame, rolling-window, time-seriesStripe, Shopify, Adobe
28Customers Driving 80% of Revenuerunning-total, pareto, window-functionsAmazon, Salesforce, Uber

Hard

#ProblemTopicsAsked at
29Longest Activity Streak per Usergaps-and-islands, ranking, datesDuolingo, Strava, Meta, Google
30Merge Overlapping Subscription Periodsintervals, gaps-and-islands, running-maxNetflix, Spotify, Amazon, Apple
31Peak Concurrent Sessions per Dayintervals, sweep-line, running-totalNetflix, Zoom, Twitch, AWS
32Build an SCD Type 2 Dimension from Daily Snapshotsscd2, gaps-and-islands, data-modelingDatabricks, Snowflake, Airbnb, any data warehouse team
33Org Chart: All Reports Under Each Managerrecursive-cte, hierarchy, graphsMicrosoft, Workday, Google, SAP
34Forward-Fill Missing Sensor Readingsforward-fill, window-functions, time-seriesTesla, Siemens, Bloomberg, Two Sigma
35Classify Users as New, Retained, Resurrected or Churnedgrowth-accounting, retention, self-joinMeta, Spotify, Snap, Robinhood
36p95 Latency per Endpoint (Nearest-Rank)percentiles, window-functions, observabilityDatadog, Google, AWS, Cloudflare
37Trip Cancellation Rate Excluding Banned Usersjoins, ratios, filteringUber, Lyft, DoorDash
38Products Frequently Bought Togetherself-join, market-basket, combinatoricsAmazon, Instacart, Walmart, Target
39Time Spent in Each Ticket Statuslead, event-log, durationsAtlassian, ServiceNow, Zendesk, Salesforce
40Exponential Moving Average with a Recursive CTErecursive-cte, moving-average, time-seriesTwo Sigma, Citadel, Robinhood, Bloomberg
41Remove Near-Duplicate Events Within 5 Secondsdeduplication, lag, event-timeSegment, Amplitude, Meta, Snowflake

By pattern

PatternProblems
Window frames / moving averages05, 11, 12, 27, 28, 40
Ranking / dedup / top-N01, 02, 08, 13, 24, 29
Gaps & islands / sessionization14, 15, 29, 30, 32, 41
Retention / cohorts / growth04, 17, 18, 20, 35
Funnels / sequences / attribution16, 21, 26
Intervals & time09, 25, 30, 31, 39
Recursive CTEs12, 20, 33, 35, 40
Data engineering specific (CDC, SCD2, dedup)02, 24, 32, 34, 41