Interactive SQL practice

300 SQL Challenges & Exercises

Practice SQL online with 300 interactive challenges built around realistic data. Start with 92 free exercises, get instant feedback, and progress from SELECT basics to Advanced SQL.

Free exercise
Instant feedback

Start by writing a real SQL query

Open the schema, inspect the sample data, run your answer, and see the result immediately.

Try Select All Employees

300 SQL challenges

Open Practice Arena
SELECT
Beginner

Select All Employees

Write a query to select all columns from the employees table. Return columns: id, first_name, last_name, email, department_id, salary, hire_date, manager_id.

WHERE
Beginner

Filter High Earners

Find employees with a salary greater than 80,000 and show id, first_name, last_name, and salary. Return columns: id, first_name, last_name, salary.

INNER JOIN
Intermediate

Revenue Per Customer

Calculate total revenue (sum of total_amount) per customer, showing customer name and total revenue, sorted by revenue descending. Return columns: customer_name, total_revenue. Order results by: total_revenue DESC.

INNER JOIN
Intermediate

Product Sales Summary

For each product, show the total quantity sold and total revenue from order_items. Include product name. Return columns: product_name, total_quantity, total_revenue. Order results by: total_revenue DESC.

Date Functions
Intermediate

Employee Hire Year Count

Count how many employees were hired in each year, ordered by year ascending. Return columns: hire_year, employee_count. Order results by: hire_year ASC.

Window Functions
Advanced

Rank Employees by Salary

Rank employees by salary within each department using RANK(), then return each employee's department, salary, and position. Return columns: first_name, last_name, department_id, salary, salary_rank. Order results by: department_id, salary_rank.

Window Functions
Advanced

Running Total of Orders

Calculate a chronological running total of order amounts and return every order with its date, amount, and cumulative revenue. Return columns: id, order_date, total_amount, running_total. Order results by: order_date.

Window Functions
Advanced
PRO

Month-over-Month Order Growth

Summarize monthly order volume and revenue, then compare each month with the previous month using LAG(). Return columns: month, orders, revenue, prev_revenue, revenue_change. Order results by: month.

Window Functions
Advanced
PRO

NTILE Salary Quartiles

Divide employees into four salary quartiles with NTILE(4), then return each employee's name, salary, and quartile. Return columns: first_name, salary, quartile. Order results by: salary DESC.

LEFT JOIN
Expert
PRO

Employee Manager Lookup

Use a self LEFT JOIN to list every employee with their direct manager's first name. Return columns: id, first_name, manager_name. Order results by: e.id.

CTE
Expert
PRO

Customer Cohort Retention

Calculate how many customers from each acquisition month (cohort) placed orders in their first month. Return columns: cohort_month, cohort_size, first_month_orders, retention_rate. Order results by: c.cohort_month.

GROUP BY
Beginner

Customers per Country

Count customers in each country, sorted by the country name. Return columns: country, customer_count. Order results by: country.

WHERE
Beginner

Pending Order List

List pending orders with their date and total amount. Return columns: id, order_date, total_amount. Order results by: order_date.

INNER JOIN
Intermediate

Department Payroll Summary

Show each department name, employee count, and total payroll. Return columns: department_name, employee_count, total_payroll. Order results by: d.id.

LEFT JOIN
Intermediate

Department Employee Coverage

Show all departments and their employee count, including departments with no employees. Return columns: department_name, employee_count. Order results by: d.id.

GROUP BY
Intermediate

Order Status Summary

Show the order count and total amount for each status. Return columns: status, order_count, total_amount. Order results by: status.

HAVING
Intermediate

Repeat Customers

Find customers who placed more than one order. Return columns: customer_name, order_count. Order results by: order_count DESC, customer_name.

Subqueries
Intermediate

Orders Above Average Value

Find orders whose total amount is greater than the average order value. Return columns: id, customer_id, total_amount. Order results by: total_amount DESC.

Aggregations
Intermediate

Low Stock Value

Calculate inventory value for products with fewer than 200 units. Return columns: name, stock, price, inventory_value. Order results by: inventory_value DESC.

Window Functions
Advanced

Dense Rank Product Prices

Use DENSE_RANK() to rank products by price inside each category while keeping equal prices at the same rank. Return columns: name, category, price, price_rank. Order results by: category, price_rank, name.

Window Functions
Advanced

Customer Order Sequence

Number each customer's orders chronologically with a window function and return the customer, order date, and sequence number. Return columns: customer_id, order_id, order_date, order_number. Order results by: customer_id, order_number.

Window Functions
Advanced
PRO

Employee Share of Department Payroll

Calculate each employee's percentage share of their department payroll. Return columns: first_name, department_id, salary, payroll_share. Order results by: department_id, salary DESC.

Window Functions
Advanced
PRO

Previous Order Comparison

Compare every order amount with the previous chronological order using LAG(), while preserving the complete order sequence. Return columns: id, order_date, total_amount, previous_amount. Order results by: order_date, id.

Window Functions
Expert
PRO

Days Between Customer Orders

Calculate the number of days between each customer's consecutive orders while retaining the current and previous order dates. Return columns: customer_id, order_id, order_date, previous_order_date, days_since_previous. Order results by: customer_id, order_date.

Showing the first 60 of 300 challenges in this learning path.

Browse and filter all challenges in the Practice Arena

Turn practice into a complete SQL learning path

Follow analyst-focused exercises for free, or unlock all 300 Core and Advanced challenges with Pro.