99 hands-on SQL exercises, from SELECT and WHERE to window functions, CTEs and table design. Use them to learn SQL from scratch, get comfortable with JOINs and GROUP BY, or prepare for a data analyst, developer or QA interview.
Every problem comes with a real-world scenario, the table schema and a sample of the expected output. The easiest way to solve them is the online trainer SQL Arena: write a query in your browser, press Submit, and your answer is checked right away against hidden data. Nothing to install — every problem runs on PostgreSQL, and many also on MySQL and ClickHouse.
- Statement — a short work scenario: what to find and how to present it.
- Tables — columns, types, primary (🔑) and foreign (→) keys.
- Expected columns and sample output — the fields the checker expects and the first rows of a correct result.
- "Solve online" link — the problem in the trainer, with an editor, a sandbox with data and automatic checking.
There are no ready-made solutions here on purpose: a problem you peeked at teaches nothing. The trainer compares your query with the reference on data you cannot see and tells you what is off: extra rows, wrong columns, wrong order.
- Over-the-Counter Medications — easy
- Customers from Berlin — easy
- Platinum-Tier Members — easy
- Long-Haul Flights — easy
- Berlin Clubs — easy
- Premium Subscriptions — easy
- 5-Star Hotels — easy
- Rock Artists — easy
- Spacious Rooms — easy
- Festivals in 2024 — easy
- Endangered Species — easy
- Savanna Residents — easy
- Product Showcase: Rename the Columns — easy
- Products Under 1000 Rubles — easy
- Delivered Orders — easy
- Customer card: projection with aliases — easy
- Products from two warehouses — easy
- Catalog Without Archive — easy
- Warehouse shelf: SKU, weight and price under readable names — easy
- Drop Unrated Reviews, Replace Empty Comments — easy
- Monthly Sales Pulse — easy
- Listening Hours by Month — easy
- Store delivery scorecard — easy
- A Customer's First Digital Footprint — easy
- Duplicate Parcel Registrations — easy
- Purchase Frequency in an Audio App — easy
- Which Customers Need a Win-Back Campaign? — easy
- From KYC Submission to Approval — easy
- Most Read Books Lookup — easy
- Kotomarket monthly orders report — medium
- Top 3 categories by revenue — medium
- Average Salary of Employees by Departments for 2023 — medium
- Book Sales Split by Genre — medium
- Analysis of courier performance by delivered packages — medium
- Client Buying Behavior Study — medium
- Sales Split by Product Category — medium
- Box Office Revenue by Popular Genres — medium
- Most prolific authors with high ratings — medium
- Second-level shelves — easy
- One-to-one, one-to-many — easy
- Row fan-out after a JOIN — easy
- Comparable apartment pairs — easy
- Employees Shown with Their Departments — easy
- Popular vehicles with multiple bookings — easy
- Package delivery tracking by shipment codes — easy
- Top players with high average score — medium
- Analyzing Airline Route Profitability — medium
- High-Volume and Profitable Products — medium
- Most Active Authors by Published Articles Count — medium
- Overloaded Hospital Departments — medium
- Top hotel rooms by average rating and revenue — medium
- Top companies by average applicant review rating — medium
- Profitable room categories for the quarter — medium
- Doctors with the highest patient complexity — medium
- Analysis of insurance policy losses by region — medium
- Top farmers' yield by crops — medium
- Find the most expensive item — easy
- Pull orders from Russian customers only — easy
- Find orders bigger than average — easy
- Customers who already ordered something — easy
- Products that nobody bought — easy
- Show every customer's order count — easy
- Cheapest pick in every category — easy
- Parcel scans after the watermark — easy
- Documentary watchers — easy
- Top Bank Clients by Transaction Amount — hard
- Quarterly Performance of Sales Managers — hard
- Top Couriers by Deliveries with Urgency Priority — hard
- Employee Earnings Breakdown — hard
- Monthly Top Tracks in Playlists — hard
- Most-Played Artists Across Playlists — hard
- Student Performance Ranking by Department with Grade Dynamics — hard
- Revenue Month-on-Month Growth — hard
- Gaps between plays — easy
- Session-start flag in an online store — easy
- Neobank Operating Balance — easy
- Each Product's Share of Total Revenue via SUM() OVER () — medium
- Staff Salaries: How Far From the Average — medium
- Student Rating by Average Grade with Group Position — medium
- Crop Variety Yield Rankings by Plot — medium
- Genre Champions Among Library Readers — hard
- Payout Trends Across Insurance Policies — hard
- Gym Member Payment Momentum — hard
- Fleet Revenue Growth by Month — hard
- Monthly Box Office Peaks by Film — hard
- Rising Stars of the Travel Agency — hard
- Repeat Visit Intervals by Doctor — hard
- Discount on Action games — easy
- Seed a batch of test orders — easy
- Spring cleaning — drop everything unpinned — easy
- Save your first journal entry — easy
- Pin every January note for the new year — easy
- Add a test user — easy
- Drop the Departments Table — easy
- Add Email Column — easy
- Drop Salary Column — easy
- Rename Column name — easy
- Normalization: split a flat book catalog into authors + books (PK/FK) — medium
- Kotomarket: split an order into 3NF — medium
This repository holds 99 problems from the free part of the trainer. SQL Arena has more than 1,400: interview questions, a SQL course from scratch, courses on analytics, ClickHouse and Kafka, duels and a leaderboard.
© SQL Arena, sql.coderang.dev