Querydrill

All 60 SQL exercises

Querydrill is SQL practice in your browser. Every exercise gives you real tables, a question and an editor. You write the query, run it as often as you like, and it is checked on the rows it returns and again on a changed copy of the data, so guesses fail and working queries pass. The exercises are listed here level by level. 6 are free without an account; Pro unlocks the rest.

Start practicing free

Level 1: Basics

SELECT, WHERE, ORDER BY, LIMIT, DISTINCT, IN, LIKE, NULL handling and CASE.

  1. Pick two columnsFree
  2. Filter rowsFree
  3. Top three earnersFree
  4. Count paid ordersFree
  5. Each country onceFree
  6. Small ordersPro
  7. Two countriesPro
  8. Pattern matchPro
  9. No managerPro
  10. Sort on two columnsPro
  11. Calculated columnPro
  12. Label with CASEPro

Level 2: Aggregation

COUNT, SUM, AVG, GROUP BY, HAVING, COUNT DISTINCT and grouping by dates.

  1. Customers per countryPro
  2. Spend per customerPro
  3. Repeat buyersPro
  4. Revenue by monthPro
  5. Average salary per departmentPro
  6. First and last orderPro
  7. Orders per statusPro
  8. Products per categoryPro
  9. Units sold per productPro
  10. Customers who orderedPro
  11. Average paid orderPro
  12. Hires per yearPro
  13. Active in several monthsPro

Level 3: Joins

Inner, left and self joins, finding rows with no match, keeping zero counts.

  1. Orders with customer namesPro
  2. Customers who never orderedPro
  3. Revenue per countryPro
  4. Everyone with a departmentPro
  5. Employee and managerPro
  6. Revenue per productPro
  7. Revenue per categoryPro
  8. Products never soldPro
  9. Headcount per departmentPro
  10. Orders per customerPro
  11. Products per orderPro
  12. Customers from the same countryPro

Level 4: Advanced

Subqueries, CTEs, RANK, DENSE_RANK, ROW_NUMBER, LAG and running totals.

  1. Above the average salaryPro
  2. Rank within departmentPro
  3. Running revenue totalPro
  4. Top earner per departmentPro
  5. Second highest salaryPro
  6. Big spendersPro
  7. Dense rankPro
  8. Change from the previous orderPro
  9. Share of revenuePro
  10. Each customer's first orderPro
  11. Month over monthPro
  12. Top two per categoryPro

Level 5: Interview classics

Nth highest salary, earns more than the manager, pivots with CASE.

  1. Third highest salaryPro
  2. Earns more than the managerPro
  3. Departments above averagePro
  4. Pivot the statusesPro

Level 6: Work mode

Requests from Marketing, Finance and Support on messy tables: text amounts, mixed date formats, duplicates and stray spaces.

  1. Clean up the country reportFree
  2. Find duplicate accountsPro
  3. Total revenue from text amountsPro
  4. Revenue by monthPro
  5. Signups per planPro
  6. Paying customers by countryPro
  7. First payment per customerPro

Try the first six exercises free.

No sign-up needed for the first six, including one Work mode task. If it works for you, Pro unlocks all 60, and a free account saves your progress across devices.

Start practicing free