SQL Challenges

13 hand-crafted challenges across Easy, Medium and Hard difficulty. Perfect for SQL interview preparation.

1
Select All Users
Retrieve all columns from the users table, limited to 20 rows.
SELECTLIMIT
Easy
2
Active Products
Find all active products, ordered by rating descending.
SELECTWHEREORDER BY
Easy
3
Orders by Status
Count how many orders exist for each status.
GROUP BYCOUNT
Easy
4
Premium Users
List all premium users showing their full name, email and city.
SELECTWHERE
Easy
5
Top Customers by Revenue
Find top 15 customers by total lifetime order value using JOIN and GROUP BY.
JOINGROUP BYSUM
Medium
6
Revenue by Category
Calculate total revenue, units sold and orders per product category.
JOINGROUP BYSUM
Medium
7
Monthly Revenue Trend
Show monthly order revenue for the last 12 months.
DATEGROUP BYSUBSTR
Medium
8
Payment Method Analysis
Analyze payment methods: success rate and total revenue per method using CASE WHEN.
CASE WHENGROUP BY
Medium
9
Department Salary Stats
For each department: headcount, avg, min and max salary.
GROUP BYAVGMIN
Medium
10
Second Highest Salary
Find employees with the second highest salary. Handle ties correctly using a subquery.
SubqueryDISTINCTOFFSET
Hard
11
Running Revenue Total
Show monthly revenue with a running cumulative total using a CTE.
CTEWITHCorrelated Subquery
Hard
12
Customer RFM Segmentation
Segment customers by Recency, Frequency and Monetary value using a CTE and CASE WHEN.
CTECASE WHENSegmentation
Hard
13
Product Performance Report
For each product: units sold, revenue, avg review and profit margin % across 3 JOINed tables.
Multi-JOINCOALESCELEFT JOIN
Hard

Want more challenges?

Upgrade to Premium for 500+ challenges, AI hints and PostgreSQL mode.