Topic
SQL & Data interview problems
Joins, window functions, aggregation and data cleaning in Python. 239 original problems, each with hidden test cases you can run in the browser.
27 easy200 medium12 hard
Showing 1–30 of 239 results
Write a SQL query that credits each conversion to the latest eligible ad impression within a 7-day lookback, then reports daily campaign metrics for January 2024.
Model answersqlwindow-functionsattributionjoinsCompute up-to-date item stock by merging starting snapshot balances with subsequent movement logs using SQL aggregations and joins.
Model answersqlaggregationjoinsCompare UNION and UNION ALL, write a NULL-safe anti-join and a top-3-per-group query, then explain star-schema roles and Type 2 history tracking for a sensor dimension.
Model answersqlwindow-functionsdata-warehousescd-type-2Process and aggregate relational records across multiple entity tables into a single denormalized fact dataset.
Auto-gradedsqlarraysdata-manipulationhash-mapConvert multi-currency sales to USD with an as-of rate join, pivot revenue by category and region, find August's top customer per region, and flag missing FX rates.
Model answersqlas-of-joinpivotwindow-functionsGroup order records by store and calendar month, then compute each month's percentage change versus the store's previous active month, handling zero totals and gaps.
Auto-gradedaggregationgroup-bywindow-functionsdictionariesProcess moderation report logs to calculate unique report ratios and aggregate key reporting metrics per reporter.
Auto-gradedarraysdictionariesdata-processingmetricsBuild a leakage-free training table at a fixed snapshot: deduplicated, arrival-aware 7-day activity features per user, plus a forward-looking 30-day purchase label.
Model answersqlfeature-engineeringpoint-in-timededuplicationBuild a fixed 7-day report of active users, first-activity cohorts, next-day return rate and revenue per active user from raw logs, with bot filtering and deduplication.
Auto-gradedcohort-analysisretentiondeduplicationhash-setsGiven department and employee tables as lists, return every employee who earns the maximum salary in their department, keeping ties and handling duplicate names.
Auto-gradedgroup-byhash-maptiesjoinsWrite five SQL queries over users, referrals and orders that measure referral conversion and revenue without losing zero-activity rows, with no window functions.
Model answersqlleft-joingroup-byhavingEmulate SQL-style reporting in Python: grouped mean and population stddev, NULL-to-zero mapping, inner joins across three tables, and RANK/DENSE_RANK within partitions.
Auto-gradedsqlgroup-byjoinswindow-functionsBuild per-campaign, per-segment fundraising metrics for August 2025 with fan-out-safe joins and cost allocation, pick the more profitable campaign, then choose extra gala invitees.
Model answersqlaggregationjoinswindow-functionsUse Excel helper columns and PivotTables to find the day with the highest clicks per watch-minute and the ISO week with the most watch time, with deterministic tie-breaks.
Model answerexcelpivot-tableiso-weekratio-metricsBuild a 7-day spend view over three tables, add rows in foreign-key order, update statuses and prices, then reason about how a price change distorts past spend.
Model answersqlviewsleft-joininsert-updateWrite one SQL query comparing control and treatment on 7-day trial conversion and on a week-long return window starting 30 days after the trial begins.
Model answersqlab-testingcohort-analysisretentionIdentify which classic concurrency anomaly a fixed read/read/write/write schedule on one shared value produces, and return the matching option letter.
Auto-gradedtransactionsconcurrencyisolation-levelsserializabilityGiven a log of ad submission rows, find the sponsors with at least one submission in week 1 and at least one in week 2, returned sorted, which tests set intersection and deduplication.
Auto-gradedsetsdeduplicationintersectiondata-manipulationFind merchants whose 30-day chargeback rate exceeds 0.5% and explain why the rate filter belongs after grouping, plus dialect quirks and performance implications.
Model answersqlgroup-byhavingaggregationBuild daily active users, rolling averages, per-user rolling counts and week-over-week retention from a UTC event log, using timezone-correct, vectorized Pandas.
Model answerpandastime-seriesgroupbyrolling-windowGroup login records by user, keep only exact-match successful ones, and report users whose successful logins span at least two distinct countries, sorted.
Auto-gradedhash-mapsetsfilteringgroup-byTurn a table of nested event lists and attribute dicts into a flat event table, per-user features, and segment conversion rates using pandas without row loops.
Model answerpandasdata-manipulationexplodegroupbyPick one top student per department from two record lists, using GPA with deterministic tie-breaks, skipping missing values, and keeping departments that have no eligible student.
Auto-gradedgroup-wise selectionleft jointie-breakingnull handlingGroup daily production records by line and month, add a per-line running total, and compute each month's defect percentage from summed counts.
Auto-gradedgroup-byhashingrunning-totalaggregationTests normalizing records from two sources with a misspelled field name, casting a numeric field to float, and concatenating the lists in order without mutating inputs.
Auto-gradeddata-cleaningdictionariesschema-alignmentconcatenationGiven user and ride records, return users with no ride in the 7-day window ending at the latest ride date, including users who never rode, sorted by user_id.
Auto-gradedanti-joindate-windowhash-setfilteringWrite a SQL query to compute 7-day revenue growth and identify top spenders per product model with tie-breaking logic based on historical purchase date.
Model answersqlwindow-functionsaggregationsjoinsBucket timestamped payments into Pacific-time Monday weeks, fill empty weeks with zero, and report weekly and trailing three-week totals.
Auto-gradedtime zonesdate bucketingrolling windowaggregationWrite a PostgreSQL query returning, per city, the mean per-ride rating in each rider's first and third months with rides, handling skipped months, unrated rides and weighting.
Model answersqlpostgresqlwindow-functionsdense-rankWrite SQL for a photo app: totals, top month, top followed user, daily KPI and follower-bucket tables in Los Angeles time, and week-1 retention cohorts.
Model answersqlwindow-functionstimezonescohort-retention