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.
Your Learning Progress
Complete exercises to earn XP and rank up your profile.
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 Specific Columns
Retrieve only the `name` and `price` columns for all records in the `products` table.
Find USA Customers
Filter the `customers` table to find the `name`, `email`, and `country` of all customers who reside in the 'USA'.
Sort Products by Price
Write a query to retrieve the `name` and `price` of all products, sorted from the most expensive to the cheapest.
Calculate Average Product Price
Calculate the average price of all products in the `products` table. Alias the result column as `average_price`.
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.
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.
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`.
Products Never Ordered
Identify all products in the database that have never been ordered. Retrieve their `name`, `category`, and `price`.
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.
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.
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`.
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).
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`.
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.