Hands-on SQL Sandbox

Interactive SQL Practice Hub

Master SQL through hands-on exercises running in your browser. Write real queries, run them against live schemas (Customers, Orders, Products), and validate your output in real-time.

501 Total Exercises
0 Solved
100% Free & Local

Your Learning Progress

Complete exercises to earn XP and rank up your profile.

0%0/501 Completed
Start First Exercise
FOUND 501 EXERCISES
beginnerSQL Basics 3m

Select All Products

Write a query to retrieve all columns and all rows from the `products` table. This is the starting point for exploring database records.

SELECT*FROM
Solve Challenge
beginnerSQL Basics 3m

Select Specific Columns

Retrieve only the `name` and `price` columns for all records in the `products` table.

SELECTColumn Selection
Solve Challenge
beginnerFiltering 4m

Find USA Customers

Filter the `customers` table to find the `name`, `email`, and `country` of all customers who reside in the 'USA'.

WHEREText Filter
Solve Challenge
beginnerSorting 4m

Sort Products by Price

Write a query to retrieve the `name` and `price` of all products, sorted from the most expensive to the cheapest.

ORDER BYDESC
Solve Challenge
beginnerAggregation 4m

Calculate Average Product Price

Calculate the average price of all products in the `products` table. Alias the result column as `average_price`.

AVGColumn Aliasing
Solve Challenge
intermediateGROUP BY 8m

Total Sales per Category

Write a query to find the total sales revenue generated (sum of `total_amount`) for each product category. Show the `category` and the sum aliased as `total_revenue`, sorted from highest to lowest revenue.

GROUP BYSUMJOINORDER BY
Solve Challenge
intermediateHAVING 8m

High-Spending Customers

Identify all customers who have spent a total of more than $500 across all their orders. Retrieve the customer's `name` and their `total_spent`. Sort the results by `total_spent` descending.

GROUP BYHAVINGSUMJOIN
Solve Challenge
intermediateJoins 7m

Retrieve Orders with Customer Details

Generate a list of all orders showing the `order_id` (alias `orders.id`), `order_date`, customer `name`, product `name`, and order `quantity`. Sort chronologically by `order_date`.

INNER JOINMulti-table Joins
Solve Challenge
intermediateJoins 8m

Products Never Ordered

Identify all products in the database that have never been ordered. Retrieve their `name`, `category`, and `price`.

LEFT JOINAnti-JoinIS NULL
Solve Challenge
intermediateSubqueries 7m

Products Priced Above Average

Retrieve the `name`, `category`, and `price` of all products that cost more than the average price of all products in the database. Sort by price ascending.

SubquerySELECT in WHEREAVG
Solve Challenge
advancedWindow Functions 12m

Cumulative Sales Running Total

Calculate a cumulative running total of order sales revenue over time. Retrieve the `order_date`, the individual order's `total_amount`, and the running total aliased as `running_total`, sorted chronologically.

Window FunctionsSUM OVERRunning Total
Solve Challenge
advancedWindow Functions 10m

Rank Customers by Total Spending

Calculate the total spending for each customer and rank them from highest spender to lowest. Display the customer's `name`, their `total_spent`, and their rank using `DENSE_RANK() OVER (...)` aliased as `spending_rank`.

DENSE_RANKGROUP BYWindow Functions
Solve Challenge
advancedDate Functions 15m

Month-over-Month Sales Growth

Calculate the month-over-month percentage growth in sales revenue. Return the year-month string (formatted as 'YYYY-MM'), the monthly revenue (aliased as `monthly_revenue`), the previous month's revenue (aliased as `prev_month_revenue`), and the percentage growth (aliased as `growth_percentage`, rounded to 2 decimal places).

LAGstrftimeWindow FunctionsROUND
Solve Challenge
advancedCTE 10m

Generate Numeric Sequences

Write a recursive Common Table Expression (CTE) to generate a single-column table containing numbers from 1 to 10. Alias the column as `num`.

WITH RECURSIVEUnion All
Solve Challenge
advancedAdvanced SQL 20m

Consecutive Days Sales Streaks

Identify consecutive days where at least one order was placed. For each consecutive streak, return the start date (`streak_start`), the end date (`streak_end`), and the number of consecutive days (`consecutive_days`). Sort by `consecutive_days` descending.

Gaps & IslandsWindow SubtractionROW_NUMBERDATE
Solve Challenge
Page 1 of 34