The Data Foundry
Built by Data with Pranjal
All Practice
Choose a guided lab or practice track
SQL Lab
Interview SQL with real data and validation
Python Lab
Data engineering Python practice
PySpark Lab
Spark code review and production fixes
Airflow Lab
DAG incidents, retries, sensors, and backfills
AWS Lab
Service choices, architecture, security, and cost
System Design Studio
Architecture trade-offs and interview framing
The Data Foundry is improving every week. If something feels unclear, broken, or missing, tell us and we will use it to improve the platform.
Inspect the data, write the solution, run validation checks, and explain the production lesson.
Labs
294
Attempted
0
Completed
Free
80
Choose a question first
Open any SQL question from the library. Once you choose one, the question navigator stays on the left so moving to the next lab is quick.
Solve this SQL interview task using the seeded tables: Second Highest Salary. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Return the third highest distinct salary from employees. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Top 3 Salaries per Department. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Latest Order per Customer. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: First and Last Order per Customer. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Running Total by Date. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: 3-Day Moving Average. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Month-over-Month Growth. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Rank Cities by Sales with Ties. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Top 10 Percent of Customers by Spend. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Customers with No Orders. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Employees Earning Above Department Average. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Orders with Missing Customer Records. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Find users who were active in both May 2026 and June 2026. A user is considered active for a month if they have at least one row in monthly_active_users for that month. Ignore NULL user_id rows and return each retained user only once.
Return customers who bought every product in the 'Analytics' category at least once through a SUCCESS order. Ignore cancelled orders and products outside the category.
Find rows that exist in current_customers_snapshot but did not exist in previous_customers_snapshot by customer_id. Existing customers with changed city/status are not added rows.
Solve this SQL interview task using the seeded tables: Same-Day Repeat Orders. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Orders and Their Immediate Previous Order. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Find Duplicate Business Keys. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Customers with Orders in Consecutive Months. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Recursive Employee Hierarchy. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Hierarchy Path from CEO to Employee. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Sessionization with a 30-Minute Gap. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
For each event date present in user_events, calculate the number of distinct non-null users active during that date and the previous six calendar days.
Solve this SQL interview task using the seeded tables: Customers Who Churned (No Orders in Last 90 Days). Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Repeat Purchase Within 7 Days. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Consecutive Login Streaks. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Gap Greater Than 30 Days Between Orders. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Median Salary. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Pareto 80 Percent Customers. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Deduplicate and Keep the Latest Record per Business Key. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: SCD Type 2 - Find Changed Customer Rows. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: SCD Type 2 - Close Old Row and Insert New Row. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Incremental Load Using Watermark. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Merge Staging into Target by Business Key. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Return the latest balance snapshot for each account. If two snapshots have the same snapshot_ts for an account, use the higher snapshot_id as the later record.
Find successful order facts where partition_date does not match event_date. These rows likely landed in the wrong date partition and need a partition repair or backfill.
Solve this SQL interview task using the seeded tables: Find Changed Rows Between Two Snapshots by Key. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Count order fact rows by load_date where customer_id is non-null but missing from the current customer dimension.
Solve this SQL interview task using the seeded tables: Current Active SCD Row per Customer. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Rewrite a Correlated Subquery to a Join. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Replace NOT IN with NOT EXISTS Safely. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Latest Row - Self Join versus Window Function. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Filter Early Before Join. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Partition-Pruning Friendly Date Filter. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Conditional Aggregation for Status Counts. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Pivot Revenue by Region Using CASE. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: GROUPING SETS / ROLLUP Style Subtotals. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Null-Safe Comparison in Change Detection. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Solve this SQL interview task using the seeded tables: Delete Duplicates and Keep the Smallest ID. Your solution should work for the visible sample data and for hidden edge-case datasets that test ties, NULLs, duplicate rows, missing keys, and boundary conditions where relevant.
Return all customers with their profile city when available. Customers without a profile should still appear with NULL city. The important part is coverage: the output must preserve every base customer row even when enrichment data is missing. This is a common production issue when optional dimension/profile tables arrive late.
Return the employees in the top two salary bands per department. If multiple employees share the same salary band, include all of them. The important part is ranking inside each group, not globally. A query that uses a global LIMIT may look correct on tiny data but fails as soon as each department needs its own leaderboard.
Aggregate bin-level inventory for the latest snapshot date and return positive stock only. The important part is matching the output grain to the report grain. Bin-level or event-level input often needs to be aggregated before it becomes a warehouse mart.
Find duplicated email addresses after normalizing email casing. Ignore rows where email is NULL. The important part is normalization before grouping. Production duplicates often hide behind casing, whitespace, or NULL values, so the query must count the same key the business system treats as identical.
Find customers who do not have any completed order. The query should be safe even when the orders table contains NULL customer_id values. The important part is NULL-safe exclusion. In production pipelines, failed events and guest checkouts often create NULL foreign keys that can break NOT IN logic.
Return dates where the warehouse temperature is higher than the previous day in the sample feed. The important part is comparing a row with the previous row in time order. A static threshold is not enough when the business asks for day-over-day movement.
Calculate the percentage of delivery records where order_date equals delivered_date. The important part is building the exact SLA numerator and denominator. Counting rows alone is not a rate, and date equality must be checked per delivery.
Find users who had at least one event exactly one day after their first recorded event date. The important part is measuring activity relative to each user's first event date. Multiple events per day should not change the user-level retention answer.
Calculate click-through rate percentage per ad as clicks divided by impressions. Avoid divide-by-zero failures. The important part is conditional counting. The metric should divide clicks by impressions, not by all events, and should avoid divide-by-zero failures.
Calculate completed-order revenue per product and category from order_items joined to products and orders. The important part is filtering to valid revenue before aggregation. Cancelled or non-completed orders can inflate downstream marts if the status filter is missed.
Compute net balance change per account and return only accounts above 10000. The important part is financial sign handling. Credits and debits move balances in opposite directions, so a plain SUM(amount) can produce a dangerously wrong report.
Return countries that qualify as large markets by population or area. The important part is translating the business rule exactly. When the rule says either threshold qualifies, using AND silently removes valid records.
Find classes with at least five distinct enrolled students. The important part is counting unique students, not enrollment events. Retry events or duplicate rows should not inflate class capacity numbers.