Basic SQL interview questions

The first 17 questions from SQL 50. They test what comes up in almost every interview: filtering correctly, counting correctly, NULLs and dates. Each one has a small trap that is easy to miss under time pressure.

In short: basic interview questions rarely need more than SELECT, WHERE, GROUP BY and one JOIN. What makes them tricky is precision: integer division in a percentage, NULL in a condition, text instead of a date, counting order lines instead of orders. Once you know these traps, each question takes a few minutes.

How practice works here

Every question runs on a real database in your browser. The tables with all their rows sit above the editor. You can run your query as often as you like; Check compares the result with the model answer and then with hidden, slightly changed data. A hard-coded value shows up there.

If you want to test yourself under time pressure like in an interview, start the stopwatch above the question. It stops as soon as you solve the question and remembers your best time. The time stays in your browser and has no effect on points. The first question on this page is free, the rest are part of Premium; you can read all of them.

The 17 questions

1. Cancellation rate as a percentage

Basic · Percentages · Aggregation and HAVING · Online shop

Task The kitchenware shop's management wants to know how many orders get cancelled. Show one row with orders (all orders), cancelled (orders with status 'cancelled') and rate_pct (the cancelled share as a percentage, rounded to one decimal place).

orders 122 rows, 5 columns
order_idcustomer_idorder_datestatusamount
500122025-11-01cancelled93.9
500242025-11-02delivered238.8
500362025-11-08delivered14.9
500432025-11-10delivered29.9
500572025-11-11delivered44.9
500652025-11-13delivered104.7
5007112025-11-16delivered17.9
5008132025-11-17delivered119
500992025-11-18delivered206.8
5010102025-11-20delivered758
5011122025-11-23delivered44.9
501212025-11-25delivered77.8
501342025-11-27delivered149
501482025-11-28delivered39.9
5015102025-12-15delivered777.9
5016142025-12-16delivered55.8
501722025-12-22delivered34.9
5018162025-12-22delivered79
5019152025-12-29delivered22.9
5020202025-12-29delivered59.8
5021212025-12-30delivered379
5022192025-12-31delivered114.7
5023172026-01-03delivered49.8
5024182026-01-08delivered79
502562026-01-14delivered44.9
5026112026-01-16delivered12.9
502792026-01-17delivered49.9
502822026-01-21delivered59.9
5029222026-01-24delivered49.9
5030242026-01-25delivered498
5031252026-02-04delivered413.9
503252026-02-05delivered34.9
5033282026-02-06cancelled34.9
5034262026-02-11delivered17.9
5035112026-02-20delivered39.9
5036212026-02-23delivered170.9
5037292026-02-25delivered49.9
5038272026-02-26delivered24.9
5039122026-03-03delivered308
5040182026-03-03delivered26.9
5041152026-03-06delivered99.6
504212026-03-07delivered403.8
5043312026-03-11delivered417.7
5044302026-03-12delivered149
5045332026-03-13delivered158
5046342026-03-19delivered189
5047322026-03-27delivered123.8
5048352026-03-30delivered93.9
5049192026-04-01delivered69.8
505022026-04-04cancelled368.9
5051342026-04-06delivered47.8
5052202026-04-16delivered119
505362026-04-22delivered258.7
505422026-04-23cancelled126.7
5055112026-04-24delivered29.9
5056362026-04-26delivered79
5057372026-04-26cancelled12.9
5058392026-04-27delivered117.7
5059382026-04-29delivered19.9
5060222026-04-30delivered59.9
5061992026-05-01delivered63.7
5062402026-05-04delivered158
5063412026-05-05delivered378
5064292026-05-14delivered228.7
5065432026-05-17delivered74.7
5066452026-05-25cancelled39.9
5067442026-05-27delivered69.8
5068462026-05-31delivered80.7
5069272026-06-04delivered97.7
5070312026-06-09delivered68.7
5071182026-06-10delivered189
5072192026-06-11delivered57.7
5073352026-06-13delivered149
5074472026-06-19delivered119
5075492026-06-20delivered39.9
5076482026-06-23delivered49.9
5077422026-06-25delivered19.9
5078512026-06-27delivered34.9
5079392026-07-01delivered59.7
5080502026-07-01delivered25.8
5081452026-07-02delivered188.8
5082192026-07-04delivered134.4
5083532026-07-12delivered83.7
5084522026-07-14delivered77.8
5085382026-07-15delivered129.7
5086542026-07-15delivered418.8
5087462026-07-17delivered59.8
5088292026-07-19delivered188.9
5089362026-07-19delivered124.7
5090452026-07-27delivered14.9
5091412026-07-29delivered19.9
5092582026-08-01delivered99.8
5093562026-08-05delivered74.7
5094532026-08-06delivered98.9
5095592026-08-07delivered22.9
5096182026-08-12delivered1157
5097612026-08-16delivered44.7
5098292026-08-20delivered105.7
5099602026-08-24delivered307
5100392026-08-27delivered103.9
5101442026-08-28delivered243.8
5102312026-08-31delivered128.9
5103542026-08-31delivered298
5104422026-09-01delivered388.9
5105472026-09-01delivered124.7
5106632026-09-06cancelled14.9
5107642026-09-06delivered62.8
5108652026-09-06cancelled208.6
5109622026-09-11delivered34.9
5110272026-09-18delivered29.9
5111422026-09-20delivered104.7
5112412026-09-21delivered24.9
5113462026-09-27delivered94.6
5114662026-09-28delivered29.9
5115672026-10-01delivered34.9
5116512026-10-07delivered69.8
5117532026-10-07cancelled34.9
5118702026-10-09delivered211.9
5119642026-10-16delivered698
5120682026-10-21delivered183.9
5121692026-10-27shipped159.4
5122272026-10-30shipped118.9

2. Signed up but never ordered

Basic · Anti-join · Dates · Marketing

Task Marketing sends a reminder to customers who signed up but have never placed an order (not even a cancelled one). Anyone who joined very recently doesn't get it yet: the signup must be at least 30 days before the cut-off date of 31 October 2026. Show customer_id, name and signup_date for these customers, sorted by signup_date.

customers 70 rows, 6 columns
customer_idnameemailcitysignup_datechannel
1Samuel Wardsamuel.ward@example.comAustin2025-10-07Newsletter
2Owen Robinsonowen.robinson@example.comDenver2025-08-02Referral
3Liam Martinliam.martin@example.comChicago2025-09-17Search
4Thomas Hughesthomas.hughes@example.comBristol2025-09-07Search
5Chloe Lewischloe.lewis@example.comBristol2025-09-03Newsletter
6Connor Hallconnor.hall@example.comNew York2025-07-07Referral
7Lily Robinsonlily.robinson@example.comGlasgow2025-07-31Newsletter
8James Thomasjames.thomas@example.comGlasgow2025-07-02Search
9Aisha Greenaisha.green@example.comChicago2025-07-16Newsletter
10Sophia Murphysophia.murphy@example.comBirmingham2025-08-03Search
11Emily Harrisemily.harris@example.comLeeds2025-11-08Search
12Hannah Thomashannah.thomas@example.comNULL2025-11-16Search
13Ethan Hallethan.hall@example.comAustin2025-11-13Search
14Lucas Pricelucas.price@example.comLeeds2025-11-26Newsletter
15Priya Harrispriya.harris@example.comNew York2025-12-05Newsletter
16Lucas Reedlucas.reed@example.comSeattle2025-12-01Search
17Fiona Campbellfiona.campbell@example.comDenver2025-12-11Search
18Ryan Wrightryan.wright@example.comChicago2025-12-14Social media
19Priya Evanspriya.evans@example.comDenver2025-12-26Search
20Grace Campbellgrace.campbell@example.comDenver2025-12-26Search
21Aisha Priceaisha.price@example.comNew York2025-12-30Referral
22Zoe Harriszoe.harris@example.comNew York2026-01-11Newsletter
23Liam Brownliam.brown@example.comManchester2026-01-15Newsletter
24Olivia Taylorolivia.taylor@example.comDenver2026-02-03Search
25Aisha Wilsonaisha.wilson@example.comAustin2026-02-13Search
26Megan Reedmegan.reed@example.comGlasgow2026-01-28Search
27Amelia GreenNULLBristol2026-02-04Search
28Kevin Wilsonkevin.wilson@example.comBirmingham2026-02-06Search
29Isla Morganisla.morgan@example.comLondon2026-02-11Search
30Liam Hallliam.hall@example.comBristol2026-02-22Referral
31Zoe Turnerzoe.turner@example.comBirmingham2026-02-24Search
32Daniel Evansdaniel.evans@example.comChicago2026-03-05Newsletter
33Emily Wrightemily.wright@example.comLondon2026-03-07Search
34Connor Taylorconnor.taylor@example.comSeattle2026-03-11Search
35Olivia Reedolivia.reed@example.comNew York2026-03-24Social media
36Kevin Martinkevin.martin@example.comBirmingham2026-04-01Referral
37Emily Daviesemily.davies@example.comAustin2026-04-09Search
38Ruby Johnsonruby.johnson@example.comNULL2026-04-08Social media
39Henry Campbellhenry.campbell@example.comGlasgow2026-04-10Newsletter
40Ethan Murphyethan.murphy@example.comBristol2026-04-24Newsletter
41Ethan Martinethan.martin@example.comManchester2026-05-01Referral
42Liam Campbellliam.campbell@example.comAustin2026-04-30Search
43Holly Harrisholly.harris@example.comNew York2026-05-10Search
44Aaron Smithaaron.smith@example.comManchester2026-05-13Newsletter
45Aisha Bakeraisha.baker@example.comDenver2026-05-19Social media
46Isla Bennettisla.bennett@example.comGlasgow2026-05-18Social media
47Chloe Davieschloe.davies@example.comLeeds2026-06-05Newsletter
48Thomas Robinsonthomas.robinson@example.comBoston2026-06-03Search
49Marcus Evansmarcus.evans@example.comManchester2026-06-15Newsletter
50Oliver Wrightoliver.wright@example.comBristol2026-06-10Search
51Thomas Johnsonthomas.johnson@example.comGlasgow2026-06-18Search
52Sophia Reedsophia.reed@example.comLondon2026-06-24Search
53Fiona Clarkefiona.clarke@example.comLeeds2026-07-02Referral
54Liam HallLIAM.HALL@EXAMPLE.COMBristol2026-07-08Search
55Lily Thomaslily.thomas@example.comBoston2026-07-14Search
56Chloe Robinsonchloe.robinson@example.comBristol2026-07-26Search
57Hannah Campbellhannah.campbell@example.comBoston2026-07-20Social media
58Ruby Morganruby.morgan@example.comNew York2026-07-29Search
59Sophia Smithsophia.smith@example.comLondon2026-07-31Newsletter
60Ava Martinava.martin@example.comBirmingham2026-08-11Social media
61Jack Halljack.hall@example.comNULL2026-08-13Newsletter
62Grace Coopergrace.cooper@example.comChicago2026-08-25Search
63Connor Priceconnor.price@example.comManchester2026-08-23Search
64Marcus Walkermarcus.walker@example.comBristol2026-09-04Social media
65Holly Brownholly.brown@example.comDenver2026-09-06Search
66Priya EvansPriya.Evans@example.com Denver2026-09-19Search
67Carlos Garciacarlos.garcia@example.comChicago2026-09-19Social media
68Priya Thomaspriya.thomas@example.comBristol2026-09-29Search
69Mia Reedmia.reed@example.comChicago2026-10-02Search
70Marcus Turnermarcus.turner@example.comBoston2026-10-04Newsletter
orders 122 rows, 5 columns
order_idcustomer_idorder_datestatusamount
500122025-11-01cancelled93.9
500242025-11-02delivered238.8
500362025-11-08delivered14.9
500432025-11-10delivered29.9
500572025-11-11delivered44.9
500652025-11-13delivered104.7
5007112025-11-16delivered17.9
5008132025-11-17delivered119
500992025-11-18delivered206.8
5010102025-11-20delivered758
5011122025-11-23delivered44.9
501212025-11-25delivered77.8
501342025-11-27delivered149
501482025-11-28delivered39.9
5015102025-12-15delivered777.9
5016142025-12-16delivered55.8
501722025-12-22delivered34.9
5018162025-12-22delivered79
5019152025-12-29delivered22.9
5020202025-12-29delivered59.8
5021212025-12-30delivered379
5022192025-12-31delivered114.7
5023172026-01-03delivered49.8
5024182026-01-08delivered79
502562026-01-14delivered44.9
5026112026-01-16delivered12.9
502792026-01-17delivered49.9
502822026-01-21delivered59.9
5029222026-01-24delivered49.9
5030242026-01-25delivered498
5031252026-02-04delivered413.9
503252026-02-05delivered34.9
5033282026-02-06cancelled34.9
5034262026-02-11delivered17.9
5035112026-02-20delivered39.9
5036212026-02-23delivered170.9
5037292026-02-25delivered49.9
5038272026-02-26delivered24.9
5039122026-03-03delivered308
5040182026-03-03delivered26.9
5041152026-03-06delivered99.6
504212026-03-07delivered403.8
5043312026-03-11delivered417.7
5044302026-03-12delivered149
5045332026-03-13delivered158
5046342026-03-19delivered189
5047322026-03-27delivered123.8
5048352026-03-30delivered93.9
5049192026-04-01delivered69.8
505022026-04-04cancelled368.9
5051342026-04-06delivered47.8
5052202026-04-16delivered119
505362026-04-22delivered258.7
505422026-04-23cancelled126.7
5055112026-04-24delivered29.9
5056362026-04-26delivered79
5057372026-04-26cancelled12.9
5058392026-04-27delivered117.7
5059382026-04-29delivered19.9
5060222026-04-30delivered59.9
5061992026-05-01delivered63.7
5062402026-05-04delivered158
5063412026-05-05delivered378
5064292026-05-14delivered228.7
5065432026-05-17delivered74.7
5066452026-05-25cancelled39.9
5067442026-05-27delivered69.8
5068462026-05-31delivered80.7
5069272026-06-04delivered97.7
5070312026-06-09delivered68.7
5071182026-06-10delivered189
5072192026-06-11delivered57.7
5073352026-06-13delivered149
5074472026-06-19delivered119
5075492026-06-20delivered39.9
5076482026-06-23delivered49.9
5077422026-06-25delivered19.9
5078512026-06-27delivered34.9
5079392026-07-01delivered59.7
5080502026-07-01delivered25.8
5081452026-07-02delivered188.8
5082192026-07-04delivered134.4
5083532026-07-12delivered83.7
5084522026-07-14delivered77.8
5085382026-07-15delivered129.7
5086542026-07-15delivered418.8
5087462026-07-17delivered59.8
5088292026-07-19delivered188.9
5089362026-07-19delivered124.7
5090452026-07-27delivered14.9
5091412026-07-29delivered19.9
5092582026-08-01delivered99.8
5093562026-08-05delivered74.7
5094532026-08-06delivered98.9
5095592026-08-07delivered22.9
5096182026-08-12delivered1157
5097612026-08-16delivered44.7
5098292026-08-20delivered105.7
5099602026-08-24delivered307
5100392026-08-27delivered103.9
5101442026-08-28delivered243.8
5102312026-08-31delivered128.9
5103542026-08-31delivered298
5104422026-09-01delivered388.9
5105472026-09-01delivered124.7
5106632026-09-06cancelled14.9
5107642026-09-06delivered62.8
5108652026-09-06cancelled208.6
5109622026-09-11delivered34.9
5110272026-09-18delivered29.9
5111422026-09-20delivered104.7
5112412026-09-21delivered24.9
5113462026-09-27delivered94.6
5114662026-09-28delivered29.9
5115672026-10-01delivered34.9
5116512026-10-07delivered69.8
5117532026-10-07cancelled34.9
5118702026-10-09delivered211.9
5119642026-10-16delivered698
5120682026-10-21delivered183.9
5121692026-10-27shipped159.4
5122272026-10-30shipped118.9

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

3. Overdue invoices with no payment

Basic · Anti-join · Dates · Finance

Task The cut-off date is 30 June 2026. Accounts receivable wants to call the customers who haven't paid anything at all first. Show every invoice whose due_date is before the cut-off and that has no payment whatsoever: invoice_id, customer, due_date and amount, oldest due date first.

invoices 60 rows, 5 columns
invoice_idcustomerinvoice_datedue_dateamount
26001Northgate Cycles Ltd2026-01-032026-02-0226959.83
26002Riverside Bike Co.2026-01-062026-02-0514721.94
26003Hillcrest Cycle Shop2026-01-082026-02-0716992.65
26004Pedal Point Inc.2026-01-122026-02-1123417.22
26005Urban Wheels Online2026-01-152026-03-1628124.62
26006Summit Outdoor Supply2026-01-172026-02-1620273.54
26007Coastline Cycles2026-01-212026-02-2012687.37
26008Greenway Bikes2026-01-232026-02-2211730.56
26009Two Wheel Depot2026-01-262026-02-2519622.5
26010Maple Street Cycles2026-01-292026-02-1215772.49
26011Northgate Cycles Ltd2026-02-032026-03-0534472.71
26012Riverside Bike Co.2026-02-052026-03-0721466.08
26013Hillcrest Cycle Shop2026-02-092026-03-1120975.08
26014Pedal Point Inc.2026-02-122026-03-1430082.56
26015Urban Wheels Online2026-02-142026-04-1540785.91
26016Summit Outdoor Supply2026-02-182026-03-2024787.09
26017Coastline Cycles2026-02-212026-03-2316231.53
26018Greenway Bikes2026-02-242026-03-2614692.65
26019Two Wheel Depot2026-02-262026-03-2826205.7
26020Maple Street Cycles2026-02-262026-03-1219640.44
26021Northgate Cycles Ltd2026-03-032026-04-0254429.19
26022Riverside Bike Co.2026-03-062026-04-0532466.62
26023Hillcrest Cycle Shop2026-03-082026-04-0734701.33
26024Pedal Point Inc.2026-03-112026-04-1052082.83
26025Urban Wheels Online2026-03-142026-05-1359991.26
26026Summit Outdoor Supply2026-03-172026-04-1637796.33
26027Coastline Cycles2026-03-202026-04-1924397.37
26028Greenway Bikes2026-03-232026-04-2221785.83
26029Two Wheel Depot2026-03-272026-04-2639812.27
26030Maple Street Cycles2026-03-292026-04-1218452.9
26031Northgate Cycles Ltd2026-04-022026-05-0259320
26032Riverside Bike Co.2026-04-062026-05-0637402.19
26033Hillcrest Cycle Shop2026-04-082026-05-0842329.35
26034Pedal Point Inc.2026-04-112026-05-1161184.01
26035Urban Wheels Online2026-04-142026-06-1375122.1
26036Summit Outdoor Supply2026-04-182026-05-1842952.05
26037Coastline Cycles2026-04-202026-05-2029968.46
26038Greenway Bikes2026-04-242026-05-2425966.97
26039Two Wheel Depot2026-04-262026-05-2650138.68
26040Maple Street Cycles2026-04-282026-05-1227754.11
26041Northgate Cycles Ltd2026-05-032026-06-0265530.8
26042Riverside Bike Co.2026-05-062026-06-0537631.02
26043Hillcrest Cycle Shop2026-05-082026-06-0741637.92
26044Pedal Point Inc.2026-05-112026-06-1057840.47
26045Urban Wheels Online2026-05-142026-07-1368239.27
26046Summit Outdoor Supply2026-05-172026-06-1644576.3
26047Coastline Cycles2026-05-212026-06-2028255.84
26048Greenway Bikes2026-05-242026-06-2325800.16
26049Two Wheel Depot2026-05-262026-06-2546653.8
26050Maple Street Cycles2026-05-292026-06-1221711
26051Northgate Cycles Ltd2026-06-032026-07-0348415.21
26052Riverside Bike Co.2026-06-062026-07-0627191.07
26053Hillcrest Cycle Shop2026-06-092026-07-0932156.21
26054Pedal Point Inc.2026-06-122026-07-1246139.99
26055Urban Wheels Online2026-06-302026-08-2955652
26056Summit Outdoor Supply2026-06-172026-07-1737295.37
26057Coastline Cycles2026-06-202026-07-2026031.62
26058Greenway Bikes2026-06-232026-07-2321187.55
26059Two Wheel Depot2026-06-272026-07-2741200.86
26060Maple Street Cycles2026-06-282026-07-1214292.64
payments 48 rows, 4 columns
payment_idinvoice_idpayment_dateamount
1260012026-01-3126959.83
2260022026-01-3114721.94
3260032026-02-0216992.65
4260042026-02-0823417.22
5260102026-02-0915772.49
6260082026-02-1911730.56
7260092026-02-259800
8260112026-03-0334472.71
9260122026-03-0721466.08
10260132026-03-0920975.08
11260202026-03-0919640.44
12260142026-03-1130082.56
13260072026-03-1312687.37
14260052026-03-1628124.62
15260062026-03-1620273.54
16260092026-03-279822.5
17260192026-03-2813100
18260212026-03-2854429.19
19260222026-03-3032466.62
20260232026-04-0534701.33
21260242026-04-0552082.83
22260302026-04-0918452.9
23260152026-04-1040785.91
24260172026-04-1710000
25260282026-04-2221785.83
26260162026-04-2524787.09
27260292026-04-2619900
28260192026-04-2713105.7
29260312026-05-0159320
30260322026-05-0537402.19
31260332026-05-0542329.35
32260342026-05-0661184.01
33260402026-05-1027754.11
34260252026-05-1159991.26
35260262026-05-1137796.33
36260382026-05-2425966.97
37260292026-05-2619912.27
38260392026-05-2625000
39260412026-06-0165530.8
40260432026-06-0241637.92
41260422026-06-0537631.02
42260502026-06-0821711
43260442026-06-0957840.47
44260352026-06-1375122.1
45260482026-06-2225800.16
46260362026-06-2342952.05
47260392026-06-2525138.68
48260492026-06-2523300

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

4. Payments imported twice

Basic · Duplicates · Aggregation and HAVING · Finance

Task When the bank statements were imported, some payments came in twice or three times, each copy with a new payment_id. A payment counts as a duplicate if invoice_id, payment_date and amount are the same. Part payments on the same invoice on different days are not duplicates. For every payment that appears more than once, show invoice_id, payment_date, amount and copies (how many times it appears).

payments 52 rows, 4 columns
payment_idinvoice_idpayment_dateamount
1260012026-01-3126959.83
2260022026-01-3114721.94
3260032026-02-0216992.65
4260042026-02-0823417.22
5260102026-02-0915772.49
6260082026-02-1911730.56
7260092026-02-259800
8260112026-03-0334472.71
9260122026-03-0721466.08
10260132026-03-0920975.08
11260202026-03-0919640.44
12260142026-03-1130082.56
13260072026-03-1312687.37
14260052026-03-1628124.62
15260062026-03-1620273.54
16260092026-03-279822.5
17260192026-03-2813100
18260212026-03-2854429.19
19260222026-03-3032466.62
20260232026-04-0534701.33
21260242026-04-0552082.83
22260302026-04-0918452.9
23260152026-04-1040785.91
24260172026-04-1710000
25260282026-04-2221785.83
26260162026-04-2524787.09
27260292026-04-2619900
28260192026-04-2713105.7
29260312026-05-0159320
30260322026-05-0537402.19
31260332026-05-0542329.35
32260342026-05-0661184.01
33260402026-05-1027754.11
34260252026-05-1159991.26
35260262026-05-1137796.33
36260382026-05-2425966.97
37260292026-05-2619912.27
38260392026-05-2625000
39260412026-06-0165530.8
40260432026-06-0241637.92
41260422026-06-0537631.02
42260502026-06-0821711
43260442026-06-0957840.47
44260352026-06-1375122.1
45260482026-06-2225800.16
46260362026-06-2342952.05
47260392026-06-2525138.68
48260492026-06-2523300
101260312026-05-0159320
102260392026-05-2625000
103260392026-05-2625000
104260062026-03-1620273.54

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

5. Who doesn't report to Tom Bradley?

Basic · NULL traps · Filtering · HR

Task For a leadership survey, everyone who does not report directly to Tom Bradley (employee_id 2) should get the questionnaire. The managing director, who has nobody above her, is explicitly included. Show employee_id, first_name, last_name and manager_id, sorted by employee_id.

employees 10 rows, 7 columns
employee_idfirst_namelast_namedepartmentsalaryhire_datemanager_id
1KarenMitchellManagement936002018-01-02NULL
2TomBradleySales624002019-04-011
3JuliaReyesSales468002021-06-152
4MarcusAllenSales492002020-09-012
5SarahLongWarehouse396002022-02-011
6FelixTurnerWarehouse354002024-03-185
7NinaCooperAccounting528002019-10-011
8DavidRossCustomer service384002023-05-022
9LauraHughesCustomer serviceNULL2025-09-012
10PaulWardAccounting432002022-11-147

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

6. Who is still on probation?

Basic · Dates · Filtering · HR

Task The probationary period lasts six months from the hire date. Who is on probation on the reference date of 15 February 2026? That means people who have already started by that date and whose probation ends after it. Show first_name, last_name, hire_date and probation_end (hire date plus six months, as a YYYY-MM-DD date).

employees 12 rows, 7 columns
employee_idfirst_namelast_namedepartmentsalaryhire_datemanager_id
1KarenMitchellManagement936002018-01-02NULL
2TomBradleySales624002019-04-011
3JuliaReyesSales468002021-06-152
4MarcusAllenSales492002020-09-012
5SarahLongWarehouse396002022-02-011
6FelixTurnerWarehouse354002024-03-185
7NinaCooperAccounting528002019-10-011
8DavidRossCustomer service384002023-05-022
9LauraHughesCustomer serviceNULL2025-09-012
10PaulWardAccounting432002022-11-147
12LilyGrantWarehouse360002026-03-015
13BenCarterCustomer service372002025-10-152

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

7. Campaigns that ran in October

Basic · Dates · Filtering · Marketing

Task For the October 2026 report, marketing needs every campaign that ran for at least one day that month, even if it started earlier or ends later. Show name, channel, start_date and end_date, sorted by start_date, then by name for equal start dates.

campaigns 14 rows, 6 columns
campaign_idnamechannelstart_dateend_datecost
1Paid search H1 2025Paid Search2025-01-012025-06-30120
2Paid social spring 2025Paid Social2025-03-012025-05-31160
3Email newsletter (ongoing)Email2025-01-012026-12-31360
4Affiliate program sports blogsAffiliate2025-01-012026-12-31240
5Paid search H2 2025Paid Search2025-07-012025-12-31420
6Paid social summer 2025Paid Social2025-06-152025-08-31180
7Email Black Friday week 2025Email2025-11-242025-12-0140
8Paid social Black Friday week 2025Paid Social2025-11-202025-12-01230
9Paid search H1 2026Paid Search2026-01-012026-06-30450
10Paid social fitness January 2026Paid Social2026-01-022026-01-31150
11Email spring sale 2026Email2026-03-022026-03-3140
12Paid search H2 2026Paid Search2026-07-012026-12-31380
13Paid social Sep/Oct 2026Paid Social2026-09-152026-10-31220
14Paid social video testPaid Social2026-05-042026-05-24120

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

8. Orders at the weekend

Basic · Dates · Aggregation and HAVING · Online shop

Task Is weekend customer service worth it? For all orders that aren't cancelled, show two rows: day_type ('Weekend' for Saturday and Sunday, otherwise 'Weekday'), orders and revenue (sum of amount, rounded to 2 decimal places).

orders 122 rows, 5 columns
order_idcustomer_idorder_datestatusamount
500122025-11-01cancelled93.9
500242025-11-02delivered238.8
500362025-11-08delivered14.9
500432025-11-10delivered29.9
500572025-11-11delivered44.9
500652025-11-13delivered104.7
5007112025-11-16delivered17.9
5008132025-11-17delivered119
500992025-11-18delivered206.8
5010102025-11-20delivered758
5011122025-11-23delivered44.9
501212025-11-25delivered77.8
501342025-11-27delivered149
501482025-11-28delivered39.9
5015102025-12-15delivered777.9
5016142025-12-16delivered55.8
501722025-12-22delivered34.9
5018162025-12-22delivered79
5019152025-12-29delivered22.9
5020202025-12-29delivered59.8
5021212025-12-30delivered379
5022192025-12-31delivered114.7
5023172026-01-03delivered49.8
5024182026-01-08delivered79
502562026-01-14delivered44.9
5026112026-01-16delivered12.9
502792026-01-17delivered49.9
502822026-01-21delivered59.9
5029222026-01-24delivered49.9
5030242026-01-25delivered498
5031252026-02-04delivered413.9
503252026-02-05delivered34.9
5033282026-02-06cancelled34.9
5034262026-02-11delivered17.9
5035112026-02-20delivered39.9
5036212026-02-23delivered170.9
5037292026-02-25delivered49.9
5038272026-02-26delivered24.9
5039122026-03-03delivered308
5040182026-03-03delivered26.9
5041152026-03-06delivered99.6
504212026-03-07delivered403.8
5043312026-03-11delivered417.7
5044302026-03-12delivered149
5045332026-03-13delivered158
5046342026-03-19delivered189
5047322026-03-27delivered123.8
5048352026-03-30delivered93.9
5049192026-04-01delivered69.8
505022026-04-04cancelled368.9
5051342026-04-06delivered47.8
5052202026-04-16delivered119
505362026-04-22delivered258.7
505422026-04-23cancelled126.7
5055112026-04-24delivered29.9
5056362026-04-26delivered79
5057372026-04-26cancelled12.9
5058392026-04-27delivered117.7
5059382026-04-29delivered19.9
5060222026-04-30delivered59.9
5061992026-05-01delivered63.7
5062402026-05-04delivered158
5063412026-05-05delivered378
5064292026-05-14delivered228.7
5065432026-05-17delivered74.7
5066452026-05-25cancelled39.9
5067442026-05-27delivered69.8
5068462026-05-31delivered80.7
5069272026-06-04delivered97.7
5070312026-06-09delivered68.7
5071182026-06-10delivered189
5072192026-06-11delivered57.7
5073352026-06-13delivered149
5074472026-06-19delivered119
5075492026-06-20delivered39.9
5076482026-06-23delivered49.9
5077422026-06-25delivered19.9
5078512026-06-27delivered34.9
5079392026-07-01delivered59.7
5080502026-07-01delivered25.8
5081452026-07-02delivered188.8
5082192026-07-04delivered134.4
5083532026-07-12delivered83.7
5084522026-07-14delivered77.8
5085382026-07-15delivered129.7
5086542026-07-15delivered418.8
5087462026-07-17delivered59.8
5088292026-07-19delivered188.9
5089362026-07-19delivered124.7
5090452026-07-27delivered14.9
5091412026-07-29delivered19.9
5092582026-08-01delivered99.8
5093562026-08-05delivered74.7
5094532026-08-06delivered98.9
5095592026-08-07delivered22.9
5096182026-08-12delivered1157
5097612026-08-16delivered44.7
5098292026-08-20delivered105.7
5099602026-08-24delivered307
5100392026-08-27delivered103.9
5101442026-08-28delivered243.8
5102312026-08-31delivered128.9
5103542026-08-31delivered298
5104422026-09-01delivered388.9
5105472026-09-01delivered124.7
5106632026-09-06cancelled14.9
5107642026-09-06delivered62.8
5108652026-09-06cancelled208.6
5109622026-09-11delivered34.9
5110272026-09-18delivered29.9
5111422026-09-20delivered104.7
5112412026-09-21delivered24.9
5113462026-09-27delivered94.6
5114662026-09-28delivered29.9
5115672026-10-01delivered34.9
5116512026-10-07delivered69.8
5117532026-10-07cancelled34.9
5118702026-10-09delivered211.9
5119642026-10-16delivered698
5120682026-10-21delivered183.9
5121692026-10-27shipped159.4
5122272026-10-30shipped118.9

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

9. Customers with at least three orders

Basic · Aggregation and HAVING · Online shop

Task The sales table has one row per order line, not per order. Which customers have placed at least three orders that weren't cancelled? Show customer and orders (the number of distinct orders), most orders first, then by customer for ties.

sales 57 rows, 9 columns
sale_idorder_idorder_datecustomercategoryproductquantityamountstatus
120012025-06-07Harbor Fremont PartnersPaperCopy paper, 500 sheets32153.28cancelled
220012025-06-07Harbor Fremont PartnersElectronicsCross-cut shredder1129cancelled
320012025-06-07Harbor Fremont PartnersPrinter suppliesBlack ink cartridge374.7cancelled
420022025-06-12Northline Printing CoPaperNotebook A5, ruled1793.33delivered
520022025-06-12Northline Printing CoWritingBlue ballpoint pens, 10-pack1448.86delivered
620022025-06-12Northline Printing CoPrinter suppliesBlack toner XL3269.7delivered
720032025-06-27Maple Grove High SchoolWritingBlue ballpoint pens, 10-pack2173.29delivered
820032025-06-27Maple Grove High SchoolElectronics27-inch monitor3837delivered
920042025-07-08Westbrook Dental ClinicWritingYellow sticky notes, 12 pads213.98delivered
1020042025-07-08Westbrook Dental ClinicPaperNotebook A5, ruled1054.9delivered
1120052025-07-17Chloe EvansFilingLever arch file, gray1336.27delivered
1220052025-07-17Chloe EvansWritingBlue ballpoint pens, 10-pack517.45delivered
1320062025-07-26Westbrook Dental ClinicFurnitureComfort office chair2358delivered
1420072025-08-04Riverside County OfficePrinter suppliesBlack ink cartridge499.6delivered
1520072025-08-04Riverside County OfficeElectronicsMono laser printer L301219delivered
1620082025-08-06Raj PatelPaperCopy paper, 500 sheets1257.48delivered
1720082025-08-06Raj PatelFurnitureComfort office chair2358delivered
1820092025-08-26Chloe EvansElectronics27-inch monitor1279delivered
1920102025-09-05Westbrook Dental ClinicFurnitureComfort office chair1179delivered
2020102025-09-05Westbrook Dental ClinicPrinter suppliesBlack ink cartridge249.8delivered
2120112025-09-10Olivia BrooksElectronics27-inch monitor1279delivered
2220122025-09-13Northline Printing CoWritingBlue ballpoint pens, 10-pack2173.29delivered
2320132025-10-09Maple Grove High SchoolElectronics27-inch monitor3837cancelled
2420132025-10-09Maple Grove High SchoolFilingLever arch file, gray1027.9cancelled
2520142025-10-24Raj PatelWritingYellow sticky notes, 12 pads320.97delivered
2620152025-10-25Greene & Shaw LLPWritingYellow sticky notes, 12 pads855.92cancelled
2720152025-10-25Greene & Shaw LLPElectronics27-inch monitor2558cancelled
2820152025-10-25Greene & Shaw LLPPaperNotebook A5, ruled20109.8cancelled
2920162025-11-19Northline Printing CoWritingBlue ballpoint pens, 10-pack1655.84cancelled
3020172025-11-22Emily CarterFilingLever arch file, gray1439.06delivered
3120182025-11-24Chloe EvansFurnitureComfort office chair2358delivered
3220182025-11-24Chloe EvansWritingYellow sticky notes, 12 pads213.98delivered
3320192025-12-09Northline Printing CoFurnitureStanding desk2898delivered
3420192025-12-09Northline Printing CoPaperNotebook A5, ruled34186.66delivered
3520202025-12-26Lakeview Hotel LtdWritingBlue ballpoint pens, 10-pack40139.6delivered
3620202025-12-26Lakeview Hotel LtdFurnitureComfort office chair3537delivered
3720212026-01-03Westbrook Dental ClinicPaperCopy paper, 500 sheets24114.96delivered
3820212026-01-03Westbrook Dental ClinicElectronics27-inch monitor1279delivered
3920222026-01-06Northline Printing CoPrinter suppliesBlack ink cartridge374.7delivered
4020232026-02-03Lakeview Hotel LtdWritingYellow sticky notes, 12 pads213.98delivered
4120242026-02-23Chloe EvansWritingBlue ballpoint pens, 10-pack517.45delivered
4220252026-03-09Raj PatelFurnitureComfort office chair2358delivered
4320262026-03-20Harbor Fremont PartnersWritingBlue ballpoint pens, 10-pack2794.23delivered
4420262026-03-20Harbor Fremont PartnersFurnitureStanding desk2898delivered
4520262026-03-20Harbor Fremont PartnersPrinter suppliesBlack ink cartridge10249delivered
4620272026-04-07Northline Printing CoElectronicsCross-cut shredder1129delivered
4720272026-04-07Northline Printing CoFurnitureComfort office chair2358delivered
4820282026-04-08Greene & Shaw LLPPaperNotebook A5, ruled50274.5cancelled
4920282026-04-08Greene & Shaw LLPFilingLever arch file, gray1233.48cancelled
5020292026-05-09Greene & Shaw LLPFilingLever arch file, gray41114.39delivered
5120292026-05-09Greene & Shaw LLPPaperNotebook A5, ruled57312.93delivered
5220302026-05-13Maple Grove High SchoolPaperNotebook A5, ruled21115.29delivered
5320312026-06-14Olivia BrooksPaperNotebook A5, ruled1898.82shipped
5420312026-06-14Olivia BrooksElectronics27-inch monitor1279shipped
5520322026-06-19Northline Printing CoFilingLever arch file, gray1439.06open
5620322026-06-19Northline Printing CoPaperNotebook A5, ruled46252.54open
5720322026-06-19Northline Printing CoWritingBlue ballpoint pens, 10-pack2173.29open

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

10. Average lines per order

Basic · Aggregation and HAVING · Subqueries and EXISTS · Online shop

Task How many lines does an order have on average? Show a single number, lines_per_order, across all orders, rounded to 2 decimal places.

order_items 38 rows, 4 columns
order_idproduct_idquantityunit_price
10011404.79
10013252.79
10016424.9
1002223.49
10021035.49
10031604.69
100311684.9
10033502.59
100443179
100493269
100551449
10061304.79
10067106.99
100782219
100711489.9
10071204.99
100846175
1008253.49
1009101204.99
10092403.19
100992279
1010726.99
1010213.49
1011121129
10111104.99
10113122.79
10126823.9
10121404.69
101391279
101452439
101442179
10151504.79
101511289.9
10161045.49
1017233.49
1017726.99
10181804.79
101861024.9

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

11. Text after the comma

Basic · Text · Online shop

Task Many product names have the pack size or version after a comma, such as "500 sheets". For a new filter in the shop, that part should go into its own column. For every product whose name contains a comma, show name and suffix: the text after the comma without the space in front of it.

products 12 rows, 5 columns
product_idnamecategorypricestock
1Copy paper, 500 sheetsPaper4.99420
2Blue ballpoint pens, 10-packWriting3.49310
3Lever arch file, grayFiling2.79185
4Comfort office chairFurniture18912
5Standing deskFurniture4495
6Black ink cartridgePrinter supplies24.964
7Yellow sticky notes, 12 padsWriting6.990
8Mono laser printer L30Electronics2198
927-inch monitorElectronics27915
10Notebook A5, ruledPaper5.49140
11Black toner XLPrinter supplies89.922
12Cross-cut shredderElectronics1290

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

12. Big baskets

Basic · Aggregation and HAVING · JOIN · Online shop

Task The shop team wants to know how often customers buy several items at once. Show every completed order with at least three different products: order_id, order_date, products (the number of different products) and amount, sorted by order_id.

orders 239 rows, 6 columns
order_idcustomer_idorder_datecampaign_idstatusamount
500112025-01-161completed29.8
500222025-01-24NULLcompleted139.7
500332025-01-28NULLcompleted49.9
500442025-02-014completed69.8
500552025-02-073completed89.9
500662025-02-14NULLcompleted24.9
500772025-02-25NULLcancelled24.9
500882025-03-032completed139.7
500992025-03-062completed34.9
501062025-03-13NULLcompleted24.9
5011102025-03-152completed19.9
5012112025-03-17NULLcompleted49.9
5013122025-03-293cancelled89.9
5014132025-03-304completed24.9
501522025-04-033completed24.9
5016142025-04-054completed79.9
501752025-04-063completed34.9
5018102025-04-10NULLcompleted89.9
5019152025-04-123completed114.8
5020162025-04-193completed99.9
5021172025-04-26NULLcancelled79.9
502272025-04-30NULLcompleted29.9
5023182025-05-03NULLcompleted34.9
5024192025-05-08NULLcompleted89.9
5025202025-05-123completed19.9
5026212025-05-172cancelled39.9
5027222025-05-18NULLcompleted79.9
5028142025-05-241completed89.9
5029232025-05-251completed29.8
5030162025-06-013cancelled27.9
5031242025-06-01NULLcompleted19.9
5032252025-06-093completed79.9
5033262025-06-156cancelled34.9
5034272025-06-163completed24.9
5035282025-06-186completed29.8
5036292025-06-256completed19.9
5037302025-07-06NULLcompleted19.8
5038312025-07-085completed24.9
5039322025-07-105completed119.7
5040332025-07-146completed49.9
5041342025-07-246completed34.9
5042352025-07-286cancelled89.9
5043242025-07-293completed34.9
5044362025-08-016completed104.8
504552025-08-053completed29.9
5046372025-08-06NULLcancelled119
504722025-08-073completed89.9
5048382025-08-09NULLcompleted9.9
5049392025-08-146completed19.9
5050402025-08-194completed89.9
5051412025-08-29NULLcompleted89.9
5052422025-08-293completed12.9
5053432025-09-03NULLcompleted24.9
5054442025-09-065completed34.9
5055232025-09-075completed99.9
5056382025-09-123completed25.8
5057452025-09-15NULLcompleted19.9
5058462025-09-185completed99.9
5059412025-09-19NULLcompleted34.9
5060472025-09-19NULLcompleted9.9
506152025-09-24NULLcompleted24.9
5062482025-09-29NULLcompleted79.9
5063492025-09-295completed29.9
5064502025-10-08NULLcompleted129
5065142025-10-10NULLcompleted86.7
5066512025-10-115completed119.7
5067162025-10-125completed99.9
5068522025-10-145completed119.7
5069342025-10-19NULLcompleted54.8
5070212025-10-20NULLcompleted49.9
5071422025-10-205completed16.9
5072532025-10-213completed89.9
5073542025-10-24NULLcompleted54.8
5074552025-10-295completed99.9
5075562025-11-04NULLcompleted34.9
5076572025-11-055completed114.8
5077272025-11-073completed12.9
5078312025-11-07NULLcompleted59.9
5079322025-11-07NULLcompleted27.9
5080582025-11-18NULLcompleted19.9
5081592025-11-235completed89.9
5082602025-11-238completed25.8
5083122025-11-247completed47.92
5084152025-11-248completed91.84
5085482025-11-247completed55.76
5086512025-11-247completed23.92
508712025-11-257completed31.92
508872025-11-25NULLcompleted47.92
5089612025-11-253completed23.92
509062025-11-267completed39.92
5091312025-11-268completed23.92
5092562025-11-268completed10.32
5093132025-11-277cancelled91.84
5094302025-11-277completed31.92
5095382025-11-287completed103.2
5096552025-11-288completed63.92
509792025-11-298completed27.92
509852025-11-308completed15.84
5099422025-11-303completed7.92
5100442025-11-307completed48.56
5101462025-11-307completed38.24
5102472025-11-307completed31.92
5103242025-12-017completed90.24
5104622025-12-018completed15.92
5105632025-12-08NULLcompleted19.8
5106642025-12-11NULLcompleted114.8
5107142025-12-12NULLcompleted29.9
5108652025-12-155completed89.7
5109662025-12-195completed104.8
5110672025-12-25NULLcompleted34.9
5111682025-12-26NULLcompleted59.9
5112422026-01-04NULLcompleted79.9
5113692026-01-0610completed16.9
5114702026-01-063completed19.9
511522026-01-099completed89.9
5116712026-01-169completed25.8
5117722026-01-179completed89.9
5118502026-01-18NULLcompleted19.9
5119732026-01-2310completed59.9
5120742026-01-26NULLcompleted19.8
5121752026-02-029completed119
5122762026-02-064completed24.9
5123772026-02-07NULLcompleted79.9
5124782026-02-13NULLcompleted9.9
5125792026-02-15NULLcompleted104.8
5126742026-02-18NULLcompleted49.9
5127802026-02-204completed19.9
5128682026-02-24NULLcompleted12.9
5129812026-02-259completed29.9
5130522026-02-28NULLcompleted59.9
5131382026-03-013completed89.9
5132822026-03-01NULLcompleted19.9
513342026-03-02NULLcompleted29.8
5134672026-03-0311completed39.9
513522026-03-059completed44.9
5136172026-03-05NULLcompleted79.9
5137312026-03-06NULLcompleted136.7
5138832026-03-07NULLcompleted49.9
5139702026-03-0811completed47.8
5140842026-03-113completed49.8
514172026-03-12NULLcompleted19.9
5142532026-03-1211completed19.9
5143852026-03-124completed22.8
514452026-03-13NULLcancelled104.8
5145162026-03-149completed34.9
5146572026-03-15NULLcompleted107.8
5147142026-03-1611completed24.9
5148322026-03-1611completed34.9
5149542026-03-17NULLcompleted34.9
5150862026-03-17NULLcompleted25.8
5151272026-03-18NULLcompleted9.9
5152872026-03-199completed119
5153722026-03-2211completed24.9
5154882026-04-014completed29.9
5155892026-04-059completed49.9
5156902026-04-059completed102.8
5157742026-04-063completed24.9
5158912026-04-119completed29.9
5159612026-04-12NULLcompleted79.9
5160922026-04-14NULLcompleted29.9
5161932026-04-19NULLcompleted29.9
5162942026-04-249completed29.9
5163952026-04-284completed44.9
5164962026-04-309completed129
5165922026-05-07NULLcompleted55.7
5166972026-05-104completed54.8
5167982026-05-119completed14.9
5168992026-05-134completed34.9
51691002026-05-189completed129
51701012026-05-194completed148.7
5171632026-05-233cancelled24.9
51721022026-05-25NULLcompleted44.9
5173782026-06-01NULLcancelled153.9
51741032026-06-01NULLcompleted99.9
5175422026-06-029completed129
51761042026-06-04NULLcompleted49.9
51771052026-06-08NULLcompleted19.9
5178502026-06-09NULLcompleted102.8
51791062026-06-09NULLcompleted119.7
51801072026-06-164cancelled29.7
51811082026-06-229completed12.9
5182792026-06-233completed99.9
51831092026-06-264completed129
51841102026-06-26NULLcancelled24.9
5185812026-06-28NULLcompleted99.9
51861112026-07-02NULLcompleted158.9
5187772026-07-04NULLcompleted114.7
51881122026-07-04NULLcompleted39.9
51891132026-07-094cancelled19.9
51901142026-07-14NULLcompleted49.9
5191832026-07-15NULLcompleted148.7
5192762026-07-17NULLcompleted34.9
5193842026-07-17NULLcompleted34.9
51941152026-07-19NULLcompleted79.9
5195742026-07-233completed33.8
5196922026-07-2712completed19.9
51971162026-07-2712completed27.9
51981172026-07-28NULLcompleted99.9
5199672026-07-303completed29.9
52001182026-08-03NULLcompleted119
52011192026-08-073completed102.8
52021202026-08-09NULLcompleted89.9
5203932026-08-153completed47.8
52041212026-08-15NULLcompleted27.9
52051222026-08-18NULLcompleted44.9
52061022026-08-243completed89.8
52071232026-08-2512completed142.7
52081242026-08-2712completed113.7
5209952026-08-2812completed99.9
5210922026-08-313completed29.8
52111252026-08-313completed19.9
52121102026-09-01NULLcompleted42.7
52131262026-09-033completed29.9
52141272026-09-07NULLcompleted29.8
52151282026-09-13NULLcompleted24.9
52161292026-09-1913completed89.9
52171302026-09-20NULLcompleted19.9
52181172026-09-213completed96.8
52191312026-09-223completed89.9
5220502026-09-23NULLcompleted44.9
5221912026-09-23NULLcompleted89.9
5222922026-09-233completed89.9
52231322026-09-2612completed89.9
52241152026-10-03NULLcompleted25.8
52251332026-10-0413cancelled49.9
5226632026-10-05NULLcompleted24.9
52271342026-10-0513completed27.9
52281062026-10-08NULLcompleted29.9
52291192026-10-08NULLcompleted24.9
52301352026-10-1012completed24.9
5231952026-10-13NULLcompleted24.9
52321022026-10-13NULLcompleted49.9
5233982026-10-14NULLcompleted14.9
52341362026-10-164completed24.9
52351372026-10-203completed34.9
52361382026-10-2213completed34.9
52371392026-10-27NULLcompleted89.8
52381402026-10-293completed19.9
52391122026-10-31NULLcompleted104.8
order_items 297 rows, 4 columns
order_idproduct_idquantityunit_price
500121119.9
50012219.9
50021189.9
50023124.9
50029124.9
50037149.9
50047149.9
50048119.9
50051189.9
50063124.9
50079124.9
50081189.9
50082114.9
50085134.9
50095134.9
50103124.9
501121119.9
50127149.9
50131189.9
50149124.9
50159124.9
501613179.9
50175134.9
50181189.9
50191189.9
50193124.9
502016199.9
502113179.9
502219129.9
50235134.9
50241189.9
50258119.9
502623139.9
502713179.9
50281189.9
502921119.9
50292219.9
503015127.9
50318119.9
503213179.9
50335134.9
50349124.9
50352214.9
503621119.9
50371829.9
50383124.9
50391189.9
50392214.9
50407149.9
50415134.9
50421189.9
50435134.9
50441189.9
50442114.9
504511129.9
5046171119
50471189.9
50481819.9
504921119.9
50501189.9
50511189.9
50524112.9
50539124.9
50545134.9
505516199.9
50564212.9
50578119.9
505816199.9
50595134.9
50602219.9
50613124.9
506213179.9
506311129.9
5064241129
50657149.9
50658119.9
506514116.9
50661189.9
50662214.9
506716199.9
50681189.9
50682214.9
50695134.9
50698119.9
50707149.9
507114116.9
50721189.9
50735134.9
50738119.9
507416199.9
50755134.9
50761189.9
50763124.9
50774112.9
507810159.9
507915127.9
508021119.9
50811189.9
50824212.9
508310147.92
50841171.92
50843119.92
508511123.92
508519123.92
50852017.92
508611123.92
508723131.92
508810147.92
508911123.92
50907139.92
509111123.92
50926110.32
50931171.92
50933119.92
509423131.92
5095241103.2
509613163.92
50975127.92
50982227.92
50992217.92
51005127.92
51006210.32
51015127.92
51016110.32
510223131.92
51036110.32
510316179.92
510421115.92
51052229.9
51061189.9
51069124.9
510711129.9
51087149.9
510819129.9
51082019.9
51091189.9
51092114.9
51105134.9
511110159.9
511213179.9
511314116.9
511421119.9
51151189.9
51166212.9
51171189.9
511821119.9
511910159.9
51201829.9
5121171119
51229124.9
512313179.9
51242019.9
51251189.9
51252114.9
51267149.9
512721119.9
51284112.9
512911129.9
513010159.9
51311189.9
51328119.9
513321119.9
51332219.9
513423139.9
513512144.9
513613179.9
513713179.9
513714116.9
513723139.9
51387149.9
51395134.9
51396112.9
514019129.9
514021119.9
51418119.9
51428119.9
51434112.9
51432219.9
51441189.9
51442114.9
51455134.9
514613179.9
514615127.9
51479124.9
51485134.9
51495134.9
51504212.9
51512219.9
5152171119
51533124.9
515419129.9
51557149.9
51561189.9
51564112.9
51573124.9
515811129.9
515913179.9
516011129.9
516111129.9
516219129.9
516312144.9
5164241129
51654212.9
516519129.9
51665134.9
51668119.9
51672114.9
51685134.9
5169241129
5170171119
51701839.9
51713124.9
517212144.9
51733124.9
5173241129
517416199.9
5175241129
51767149.9
517721119.9
51781189.9
51784112.9
51791189.9
51792214.9
51801839.9
51814112.9
518216199.9
5183241129
51843124.9
518516199.9
5186171119
518623139.9
51877149.9
51878119.9
518712144.9
518823139.9
518921119.9
51907149.9
5191171119
51911839.9
51925134.9
51935134.9
519413179.9
519514216.9
51968119.9
519715127.9
519816199.9
519919129.9
5200171119
52011189.9
52014112.9
52021189.9
52035134.9
52036112.9
520415127.9
520512144.9
520610159.9
520611129.9
52071189.9
52074112.9
520723139.9
520813179.9
520814216.9
520916199.9
52102214.9
521121119.9
52122214.9
52126112.9
521319129.9
52142214.9
52153124.9
52161189.9
521721119.9
521813179.9
521814116.9
52191189.9
522012144.9
52211189.9
52221189.9
52231189.9
52244212.9
52257149.9
52263124.9
522715127.9
522819129.9
52299124.9
52309124.9
52319124.9
52327149.9
52332114.9
52343124.9
52355134.9
52365134.9
523710159.9
523711129.9
52388119.9
52391189.9
52392114.9

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

13. Expenses by account in Q1

Basic · JOIN · Aggregation and HAVING · Dates · Finance

Task For the quarterly report, finance needs expenses per account. For every account of type 'expense', show account_id, name and expenses: the sum of debit minus credit from all ledger entries from 1 January up to and including 31 March 2026, rounded to 2 decimal places. Highest expenses first.

accounts 13 rows, 3 columns
account_idnametype
1000Bankasset
1100Accounts receivableasset
2000Accounts payableliability
3000Equityequity
4000Sales revenuerevenue
5000Materialsexpense
6000Salaries and wagesexpense
6100Rent and occupancyexpense
6200Energyexpense
6300Travelexpense
6400Advertisingexpense
6500IT and softwareexpense
6600Repairs and maintenanceexpense
ledger 169 rows, 8 columns
entry_iddoc_noentry_dateaccount_idcost_center_iddescriptiondebitcredit
110012026-01-011000NULLOpening balance bank3200000
210012026-01-013000NULLOpening balance bank0320000
310022026-01-0361002000Rent January68000
410022026-01-0361001000Rent January46000
510022026-01-031000NULLRent January011400
610032026-01-0565001200Software licences quarter48600
710032026-01-052000NULLSoftware licences quarter04860
810042026-01-0850002000Materials purchase56177.710
910042026-01-0850002100Materials purchase34355.830
1010042026-01-082000NULLMaterials purchase090533.54
1110052026-01-2062002000Electricity and gas3416.460
1210052026-01-202000NULLElectricity and gas03416.46
1310062026-01-2860001000Payroll14469.070
1410062026-01-2860001100Payroll11248.670
1510062026-01-2860001200Payroll7764.750
1610062026-01-2860002000Payroll24648.20
1710062026-01-2860002100Payroll19865.040
1810062026-01-2860002200Payroll9919.490
1910062026-01-2860003000Payroll13339.130
2010062026-01-2860003100Payroll6905.660
2110062026-01-281000NULLPayroll0108160.01
2210072026-01-311100NULLSales invoices190302.720
2310072026-01-314000NULLSales invoices0190302.72
2410082026-01-311000NULLCustomer receipts41681.770
2510082026-01-311100NULLCustomer receipts041681.77
2610092026-02-0361002000Rent February68000
2710092026-02-0361001000Rent February46000
2810092026-02-031000NULLRent February011400
2910102026-02-0850002000Materials purchase73668.510
3010102026-02-0850002100Materials purchase44273.20
3110102026-02-082000NULLMaterials purchase0117941.71
3210112026-02-102000NULLSupplier payments988100
3310112026-02-101000NULLSupplier payments098810
3410122026-02-1264003100Ads42000
3510122026-02-122000NULLAds04200
3610132026-02-2062002000Electricity and gas3671.310
3710132026-02-202000NULLElectricity and gas03671.31
3810142026-02-2563003000Sales travel expenses1286.40
3910142026-02-251000NULLSales travel expenses01286.4
4010152026-02-2860001000Payroll14564.780
4110152026-02-2860001100Payroll11248.620
4210152026-02-2860001200Payroll7830.190
4310152026-02-2860002000Payroll24669.510
4410152026-02-2860002100Payroll19869.440
4510152026-02-2860002200Payroll9893.720
4610152026-02-2860003000Payroll13366.230
4710152026-02-2860003100Payroll6921.810
4810152026-02-281000NULLPayroll0108364.3
4910162026-02-281100NULLSales invoices249339.750
5010162026-02-284000NULLSales invoices0249339.75
5110172026-02-281000NULLCustomer receipts77712.920
5210172026-02-281100NULLCustomer receipts077712.92
5310182026-03-0361002000Rent March68000
5410182026-03-0361001000Rent March46000
5510182026-03-031000NULLRent March011400
5610192026-03-0565001200Laptop hardware32900
5710192026-03-052000NULLLaptop hardware03290
5810202026-03-0850002000Materials purchase110523.120
5910202026-03-0850002100Materials purchase67928.040
6010202026-03-082000NULLMaterials purchase0178451.16
6110212026-03-102000NULLSupplier payments125813.020
6210212026-03-101000NULLSupplier payments0125813.02
6310222026-03-1264003100Spring campaign186000
6410222026-03-122000NULLSpring campaign018600
6510232026-03-2062002000Electricity and gas3929.910
6610232026-03-202000NULLElectricity and gas03929.91
6710242026-03-2266002000Machine service24800
6810242026-03-222000NULLMachine service02480
6910252026-03-262000NULLSupplier credit note return12400
7010252026-03-2650002000Supplier credit note return01240
7110262026-03-2860001000Payroll14521.480
7210262026-03-2860001100Payroll11254.450
7310262026-03-2860001200Payroll7770.970
7410262026-03-2860002000Payroll24522.860
7510262026-03-2860002100Payroll19761.50
7610262026-03-2860002200Payroll9898.420
7710262026-03-2860003000Payroll16593.370
7810262026-03-2860003100Payroll6919.280
7910262026-03-281000NULLPayroll0111242.33
8010272026-03-311100NULLSales invoices375915.930
8110272026-03-314000NULLSales invoices0375915.93
8210282026-03-311000NULLCustomer receipts297540.710
8310282026-03-311100NULLCustomer receipts0297540.71
8410292026-04-0361002000Rent April68000
8510292026-04-0361001000Rent April46000
8610292026-04-031000NULLRent April011400
8710302026-04-0565001200Software licences quarter48600
8810302026-04-052000NULLSoftware licences quarter04860
8910312026-04-0850002000Materials purchase132153.910
9010312026-04-0850002100Materials purchase84705.120
9110312026-04-082000NULLMaterials purchase0216859.03
9210322026-04-102000NULLSupplier payments205511.070
9310322026-04-101000NULLSupplier payments0205511.07
9410332026-04-1264003100Spring campaign214000
9510332026-04-122000NULLSpring campaign021400
9610342026-04-2062002000Electricity and gas4275.470
9710342026-04-202000NULLElectricity and gas04275.47
9810352026-04-2563003000Sales travel expenses2914.70
9910352026-04-251000NULLSales travel expenses02914.7
10010362026-04-2860001000Payroll14511.120
10110362026-04-2860001100Payroll11250.530
10210362026-04-2860001200Payroll7799.380
10310362026-04-2860002000Payroll24704.10
10410362026-04-2860002100Payroll22185.090
10510362026-04-2860002200Payroll9945.030
10610362026-04-2860003000Payroll13372.530
10710362026-04-2860003100Payroll6882.320
10810362026-04-281000NULLPayroll0110650.1
10910372026-04-301100NULLSales invoices452137.920
11010372026-04-304000NULLSales invoices0452137.92
11110382026-04-301000NULLCustomer receipts235601.590
11210382026-04-301100NULLCustomer receipts0235601.59
11310392026-05-0361002000Rent May68000
11410392026-05-0361001000Rent May46000
11510392026-05-031000NULLRent May011400
11610402026-05-0850002000Materials purchase141737.720
11710402026-05-0850002100Materials purchase82231.250
11810402026-05-082000NULLMaterials purchase0223968.97
11910412026-05-102000NULLSupplier payments247394.50
12010412026-05-101000NULLSupplier payments0247394.5
12110422026-05-1264003100Ads63000
12210422026-05-122000NULLAds06300
12310432026-05-2062002000Electricity and gas4015.690
12410432026-05-202000NULLElectricity and gas04015.69
12510442026-05-272000NULLAgency credit note18500
12610442026-05-2764003100Agency credit note01850
12710452026-05-2860001000Payroll14460.250
12810452026-05-2860001100Payroll11220.170
12910452026-05-2860001200Payroll7803.770
13010452026-05-2860002000Payroll24549.870
13110452026-05-2860002100Payroll22845.090
13210452026-05-2860002200Payroll9873.460
13310452026-05-2860003000Payroll13377.780
13410452026-05-2860003100Payroll6876.770
13510452026-05-281000NULLPayroll0111007.16
13610462026-05-311100NULLSales invoices437876.580
13710462026-05-314000NULLSales invoices0437876.58
13810472026-05-311000NULLCustomer receipts396656.490
13910472026-05-311100NULLCustomer receipts0396656.49
14010482026-06-0361002000Rent June68000
14110482026-06-0361001000Rent June46000
14210482026-06-031000NULLRent June011400
14310492026-06-0565001200Laptop hardware21400
14410502026-06-0850002000Materials purchase100972.770
14510502026-06-0850002100Materials purchase65827.080
14610502026-06-082000NULLMaterials purchase0166529.85
14710512026-06-102000NULLSupplier payments232434.660
14810512026-06-101000NULLSupplier payments0232434.66
14910522026-06-1264003100Ads51000
15010522026-06-122000NULLAds05100
15110532026-06-2062002000Electricity and gas3998.690
15210532026-06-202000NULLElectricity and gas03998.69
15310542026-06-226600NULLMachine service39600
15410542026-06-222000NULLMachine service03960
15510552026-06-256300NULLSales travel expenses1742.30
15610552026-06-251000NULLSales travel expenses01742.3
15710562026-06-2860001000Payroll14454.640
15810562026-06-2860001100Payroll11163.230
15910562026-06-2860001200Payroll7807.760
16010562026-06-2860002000Payroll24532.240
16110562026-06-2860002100Payroll19864.730
16210562026-06-2860002200Payroll9885.930
16310562026-06-2860003000Payroll13419.990
16410562026-06-2860003100Payroll6874.020
16510562026-06-281000NULLPayroll0108002.54
16610572026-06-301100NULLSales invoices293910.520
16710572026-06-304000NULLSales invoices0293910.52
16810582026-06-301000NULLCustomer receipts416664.20
16910582026-06-301100NULLCustomer receipts0416664.2

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

14. Order size bands

Basic · Aggregation and HAVING · Online shop

Task Put the orders that aren't cancelled into three size bands by amount: 'small' below 50, 'medium' from 50 and below 150, 'large' from 150. Show band, orders and revenue (sum of amount, 2 decimal places), in the order small, medium, large.

orders 122 rows, 5 columns
order_idcustomer_idorder_datestatusamount
500122025-11-01cancelled93.9
500242025-11-02delivered238.8
500362025-11-08delivered14.9
500432025-11-10delivered29.9
500572025-11-11delivered44.9
500652025-11-13delivered104.7
5007112025-11-16delivered17.9
5008132025-11-17delivered119
500992025-11-18delivered206.8
5010102025-11-20delivered758
5011122025-11-23delivered44.9
501212025-11-25delivered77.8
501342025-11-27delivered149
501482025-11-28delivered39.9
5015102025-12-15delivered777.9
5016142025-12-16delivered55.8
501722025-12-22delivered34.9
5018162025-12-22delivered79
5019152025-12-29delivered22.9
5020202025-12-29delivered59.8
5021212025-12-30delivered379
5022192025-12-31delivered114.7
5023172026-01-03delivered49.8
5024182026-01-08delivered79
502562026-01-14delivered44.9
5026112026-01-16delivered12.9
502792026-01-17delivered49.9
502822026-01-21delivered59.9
5029222026-01-24delivered49.9
5030242026-01-25delivered498
5031252026-02-04delivered413.9
503252026-02-05delivered34.9
5033282026-02-06cancelled34.9
5034262026-02-11delivered17.9
5035112026-02-20delivered39.9
5036212026-02-23delivered170.9
5037292026-02-25delivered49.9
5038272026-02-26delivered24.9
5039122026-03-03delivered308
5040182026-03-03delivered26.9
5041152026-03-06delivered99.6
504212026-03-07delivered403.8
5043312026-03-11delivered417.7
5044302026-03-12delivered149
5045332026-03-13delivered158
5046342026-03-19delivered189
5047322026-03-27delivered123.8
5048352026-03-30delivered93.9
5049192026-04-01delivered69.8
505022026-04-04cancelled368.9
5051342026-04-06delivered47.8
5052202026-04-16delivered119
505362026-04-22delivered258.7
505422026-04-23cancelled126.7
5055112026-04-24delivered29.9
5056362026-04-26delivered79
5057372026-04-26cancelled12.9
5058392026-04-27delivered117.7
5059382026-04-29delivered19.9
5060222026-04-30delivered59.9
5061992026-05-01delivered63.7
5062402026-05-04delivered158
5063412026-05-05delivered378
5064292026-05-14delivered228.7
5065432026-05-17delivered74.7
5066452026-05-25cancelled39.9
5067442026-05-27delivered69.8
5068462026-05-31delivered80.7
5069272026-06-04delivered97.7
5070312026-06-09delivered68.7
5071182026-06-10delivered189
5072192026-06-11delivered57.7
5073352026-06-13delivered149
5074472026-06-19delivered119
5075492026-06-20delivered39.9
5076482026-06-23delivered49.9
5077422026-06-25delivered19.9
5078512026-06-27delivered34.9
5079392026-07-01delivered59.7
5080502026-07-01delivered25.8
5081452026-07-02delivered188.8
5082192026-07-04delivered134.4
5083532026-07-12delivered83.7
5084522026-07-14delivered77.8
5085382026-07-15delivered129.7
5086542026-07-15delivered418.8
5087462026-07-17delivered59.8
5088292026-07-19delivered188.9
5089362026-07-19delivered124.7
5090452026-07-27delivered14.9
5091412026-07-29delivered19.9
5092582026-08-01delivered99.8
5093562026-08-05delivered74.7
5094532026-08-06delivered98.9
5095592026-08-07delivered22.9
5096182026-08-12delivered1157
5097612026-08-16delivered44.7
5098292026-08-20delivered105.7
5099602026-08-24delivered307
5100392026-08-27delivered103.9
5101442026-08-28delivered243.8
5102312026-08-31delivered128.9
5103542026-08-31delivered298
5104422026-09-01delivered388.9
5105472026-09-01delivered124.7
5106632026-09-06cancelled14.9
5107642026-09-06delivered62.8
5108652026-09-06cancelled208.6
5109622026-09-11delivered34.9
5110272026-09-18delivered29.9
5111422026-09-20delivered104.7
5112412026-09-21delivered24.9
5113462026-09-27delivered94.6
5114662026-09-28delivered29.9
5115672026-10-01delivered34.9
5116512026-10-07delivered69.8
5117532026-10-07cancelled34.9
5118702026-10-09delivered211.9
5119642026-10-16delivered698
5120682026-10-21delivered183.9
5121692026-10-27shipped159.4
5122272026-10-30shipped118.9

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

15. Customers per city, including no city

Basic · NULL traps · Aggregation and HAVING · Marketing

Task To plan regional advertising, marketing counts customers per city. Customers with no city should be counted as 'unknown' rather than dropped. Show city and customers, most customers first, then alphabetically by city for ties.

customers 70 rows, 6 columns
customer_idnameemailcitysignup_datechannel
1Samuel Wardsamuel.ward@example.comAustin2025-10-07Newsletter
2Owen Robinsonowen.robinson@example.comDenver2025-08-02Referral
3Liam Martinliam.martin@example.comChicago2025-09-17Search
4Thomas Hughesthomas.hughes@example.comBristol2025-09-07Search
5Chloe Lewischloe.lewis@example.comBristol2025-09-03Newsletter
6Connor Hallconnor.hall@example.comNew York2025-07-07Referral
7Lily Robinsonlily.robinson@example.comGlasgow2025-07-31Newsletter
8James Thomasjames.thomas@example.comGlasgow2025-07-02Search
9Aisha Greenaisha.green@example.comChicago2025-07-16Newsletter
10Sophia Murphysophia.murphy@example.comBirmingham2025-08-03Search
11Emily Harrisemily.harris@example.comLeeds2025-11-08Search
12Hannah Thomashannah.thomas@example.comNULL2025-11-16Search
13Ethan Hallethan.hall@example.comAustin2025-11-13Search
14Lucas Pricelucas.price@example.comLeeds2025-11-26Newsletter
15Priya Harrispriya.harris@example.comNew York2025-12-05Newsletter
16Lucas Reedlucas.reed@example.comSeattle2025-12-01Search
17Fiona Campbellfiona.campbell@example.comDenver2025-12-11Search
18Ryan Wrightryan.wright@example.comChicago2025-12-14Social media
19Priya Evanspriya.evans@example.comDenver2025-12-26Search
20Grace Campbellgrace.campbell@example.comDenver2025-12-26Search
21Aisha Priceaisha.price@example.comNew York2025-12-30Referral
22Zoe Harriszoe.harris@example.comNew York2026-01-11Newsletter
23Liam Brownliam.brown@example.comManchester2026-01-15Newsletter
24Olivia Taylorolivia.taylor@example.comDenver2026-02-03Search
25Aisha Wilsonaisha.wilson@example.comAustin2026-02-13Search
26Megan Reedmegan.reed@example.comGlasgow2026-01-28Search
27Amelia GreenNULLBristol2026-02-04Search
28Kevin Wilsonkevin.wilson@example.comBirmingham2026-02-06Search
29Isla Morganisla.morgan@example.comLondon2026-02-11Search
30Liam Hallliam.hall@example.comBristol2026-02-22Referral
31Zoe Turnerzoe.turner@example.comBirmingham2026-02-24Search
32Daniel Evansdaniel.evans@example.comChicago2026-03-05Newsletter
33Emily Wrightemily.wright@example.comLondon2026-03-07Search
34Connor Taylorconnor.taylor@example.comSeattle2026-03-11Search
35Olivia Reedolivia.reed@example.comNew York2026-03-24Social media
36Kevin Martinkevin.martin@example.comBirmingham2026-04-01Referral
37Emily Daviesemily.davies@example.comAustin2026-04-09Search
38Ruby Johnsonruby.johnson@example.comNULL2026-04-08Social media
39Henry Campbellhenry.campbell@example.comGlasgow2026-04-10Newsletter
40Ethan Murphyethan.murphy@example.comBristol2026-04-24Newsletter
41Ethan Martinethan.martin@example.comManchester2026-05-01Referral
42Liam Campbellliam.campbell@example.comAustin2026-04-30Search
43Holly Harrisholly.harris@example.comNew York2026-05-10Search
44Aaron Smithaaron.smith@example.comManchester2026-05-13Newsletter
45Aisha Bakeraisha.baker@example.comDenver2026-05-19Social media
46Isla Bennettisla.bennett@example.comGlasgow2026-05-18Social media
47Chloe Davieschloe.davies@example.comLeeds2026-06-05Newsletter
48Thomas Robinsonthomas.robinson@example.comBoston2026-06-03Search
49Marcus Evansmarcus.evans@example.comManchester2026-06-15Newsletter
50Oliver Wrightoliver.wright@example.comBristol2026-06-10Search
51Thomas Johnsonthomas.johnson@example.comGlasgow2026-06-18Search
52Sophia Reedsophia.reed@example.comLondon2026-06-24Search
53Fiona Clarkefiona.clarke@example.comLeeds2026-07-02Referral
54Liam HallLIAM.HALL@EXAMPLE.COMBristol2026-07-08Search
55Lily Thomaslily.thomas@example.comBoston2026-07-14Search
56Chloe Robinsonchloe.robinson@example.comBristol2026-07-26Search
57Hannah Campbellhannah.campbell@example.comBoston2026-07-20Social media
58Ruby Morganruby.morgan@example.comNew York2026-07-29Search
59Sophia Smithsophia.smith@example.comLondon2026-07-31Newsletter
60Ava Martinava.martin@example.comBirmingham2026-08-11Social media
61Jack Halljack.hall@example.comNULL2026-08-13Newsletter
62Grace Coopergrace.cooper@example.comChicago2026-08-25Search
63Connor Priceconnor.price@example.comManchester2026-08-23Search
64Marcus Walkermarcus.walker@example.comBristol2026-09-04Social media
65Holly Brownholly.brown@example.comDenver2026-09-06Search
66Priya EvansPriya.Evans@example.com Denver2026-09-19Search
67Carlos Garciacarlos.garcia@example.comChicago2026-09-19Social media
68Priya Thomaspriya.thomas@example.comBristol2026-09-29Search
69Mia Reedmia.reed@example.comChicago2026-10-02Search
70Marcus Turnermarcus.turner@example.comBoston2026-10-04Newsletter

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

16. Revenue by campaign, including none

Basic · NULL traps · JOIN · Aggregation and HAVING · Marketing

Task How much revenue did the campaigns bring in during 2026? For all completed orders from 1 January 2026, show revenue (sum of amount, 2 decimal places) per campaign (the campaign name; orders without a campaign as 'no campaign'), highest revenue first.

orders 239 rows, 6 columns
order_idcustomer_idorder_datecampaign_idstatusamount
500112025-01-161completed29.8
500222025-01-24NULLcompleted139.7
500332025-01-28NULLcompleted49.9
500442025-02-014completed69.8
500552025-02-073completed89.9
500662025-02-14NULLcompleted24.9
500772025-02-25NULLcancelled24.9
500882025-03-032completed139.7
500992025-03-062completed34.9
501062025-03-13NULLcompleted24.9
5011102025-03-152completed19.9
5012112025-03-17NULLcompleted49.9
5013122025-03-293cancelled89.9
5014132025-03-304completed24.9
501522025-04-033completed24.9
5016142025-04-054completed79.9
501752025-04-063completed34.9
5018102025-04-10NULLcompleted89.9
5019152025-04-123completed114.8
5020162025-04-193completed99.9
5021172025-04-26NULLcancelled79.9
502272025-04-30NULLcompleted29.9
5023182025-05-03NULLcompleted34.9
5024192025-05-08NULLcompleted89.9
5025202025-05-123completed19.9
5026212025-05-172cancelled39.9
5027222025-05-18NULLcompleted79.9
5028142025-05-241completed89.9
5029232025-05-251completed29.8
5030162025-06-013cancelled27.9
5031242025-06-01NULLcompleted19.9
5032252025-06-093completed79.9
5033262025-06-156cancelled34.9
5034272025-06-163completed24.9
5035282025-06-186completed29.8
5036292025-06-256completed19.9
5037302025-07-06NULLcompleted19.8
5038312025-07-085completed24.9
5039322025-07-105completed119.7
5040332025-07-146completed49.9
5041342025-07-246completed34.9
5042352025-07-286cancelled89.9
5043242025-07-293completed34.9
5044362025-08-016completed104.8
504552025-08-053completed29.9
5046372025-08-06NULLcancelled119
504722025-08-073completed89.9
5048382025-08-09NULLcompleted9.9
5049392025-08-146completed19.9
5050402025-08-194completed89.9
5051412025-08-29NULLcompleted89.9
5052422025-08-293completed12.9
5053432025-09-03NULLcompleted24.9
5054442025-09-065completed34.9
5055232025-09-075completed99.9
5056382025-09-123completed25.8
5057452025-09-15NULLcompleted19.9
5058462025-09-185completed99.9
5059412025-09-19NULLcompleted34.9
5060472025-09-19NULLcompleted9.9
506152025-09-24NULLcompleted24.9
5062482025-09-29NULLcompleted79.9
5063492025-09-295completed29.9
5064502025-10-08NULLcompleted129
5065142025-10-10NULLcompleted86.7
5066512025-10-115completed119.7
5067162025-10-125completed99.9
5068522025-10-145completed119.7
5069342025-10-19NULLcompleted54.8
5070212025-10-20NULLcompleted49.9
5071422025-10-205completed16.9
5072532025-10-213completed89.9
5073542025-10-24NULLcompleted54.8
5074552025-10-295completed99.9
5075562025-11-04NULLcompleted34.9
5076572025-11-055completed114.8
5077272025-11-073completed12.9
5078312025-11-07NULLcompleted59.9
5079322025-11-07NULLcompleted27.9
5080582025-11-18NULLcompleted19.9
5081592025-11-235completed89.9
5082602025-11-238completed25.8
5083122025-11-247completed47.92
5084152025-11-248completed91.84
5085482025-11-247completed55.76
5086512025-11-247completed23.92
508712025-11-257completed31.92
508872025-11-25NULLcompleted47.92
5089612025-11-253completed23.92
509062025-11-267completed39.92
5091312025-11-268completed23.92
5092562025-11-268completed10.32
5093132025-11-277cancelled91.84
5094302025-11-277completed31.92
5095382025-11-287completed103.2
5096552025-11-288completed63.92
509792025-11-298completed27.92
509852025-11-308completed15.84
5099422025-11-303completed7.92
5100442025-11-307completed48.56
5101462025-11-307completed38.24
5102472025-11-307completed31.92
5103242025-12-017completed90.24
5104622025-12-018completed15.92
5105632025-12-08NULLcompleted19.8
5106642025-12-11NULLcompleted114.8
5107142025-12-12NULLcompleted29.9
5108652025-12-155completed89.7
5109662025-12-195completed104.8
5110672025-12-25NULLcompleted34.9
5111682025-12-26NULLcompleted59.9
5112422026-01-04NULLcompleted79.9
5113692026-01-0610completed16.9
5114702026-01-063completed19.9
511522026-01-099completed89.9
5116712026-01-169completed25.8
5117722026-01-179completed89.9
5118502026-01-18NULLcompleted19.9
5119732026-01-2310completed59.9
5120742026-01-26NULLcompleted19.8
5121752026-02-029completed119
5122762026-02-064completed24.9
5123772026-02-07NULLcompleted79.9
5124782026-02-13NULLcompleted9.9
5125792026-02-15NULLcompleted104.8
5126742026-02-18NULLcompleted49.9
5127802026-02-204completed19.9
5128682026-02-24NULLcompleted12.9
5129812026-02-259completed29.9
5130522026-02-28NULLcompleted59.9
5131382026-03-013completed89.9
5132822026-03-01NULLcompleted19.9
513342026-03-02NULLcompleted29.8
5134672026-03-0311completed39.9
513522026-03-059completed44.9
5136172026-03-05NULLcompleted79.9
5137312026-03-06NULLcompleted136.7
5138832026-03-07NULLcompleted49.9
5139702026-03-0811completed47.8
5140842026-03-113completed49.8
514172026-03-12NULLcompleted19.9
5142532026-03-1211completed19.9
5143852026-03-124completed22.8
514452026-03-13NULLcancelled104.8
5145162026-03-149completed34.9
5146572026-03-15NULLcompleted107.8
5147142026-03-1611completed24.9
5148322026-03-1611completed34.9
5149542026-03-17NULLcompleted34.9
5150862026-03-17NULLcompleted25.8
5151272026-03-18NULLcompleted9.9
5152872026-03-199completed119
5153722026-03-2211completed24.9
5154882026-04-014completed29.9
5155892026-04-059completed49.9
5156902026-04-059completed102.8
5157742026-04-063completed24.9
5158912026-04-119completed29.9
5159612026-04-12NULLcompleted79.9
5160922026-04-14NULLcompleted29.9
5161932026-04-19NULLcompleted29.9
5162942026-04-249completed29.9
5163952026-04-284completed44.9
5164962026-04-309completed129
5165922026-05-07NULLcompleted55.7
5166972026-05-104completed54.8
5167982026-05-119completed14.9
5168992026-05-134completed34.9
51691002026-05-189completed129
51701012026-05-194completed148.7
5171632026-05-233cancelled24.9
51721022026-05-25NULLcompleted44.9
5173782026-06-01NULLcancelled153.9
51741032026-06-01NULLcompleted99.9
5175422026-06-029completed129
51761042026-06-04NULLcompleted49.9
51771052026-06-08NULLcompleted19.9
5178502026-06-09NULLcompleted102.8
51791062026-06-09NULLcompleted119.7
51801072026-06-164cancelled29.7
51811082026-06-229completed12.9
5182792026-06-233completed99.9
51831092026-06-264completed129
51841102026-06-26NULLcancelled24.9
5185812026-06-28NULLcompleted99.9
51861112026-07-02NULLcompleted158.9
5187772026-07-04NULLcompleted114.7
51881122026-07-04NULLcompleted39.9
51891132026-07-094cancelled19.9
51901142026-07-14NULLcompleted49.9
5191832026-07-15NULLcompleted148.7
5192762026-07-17NULLcompleted34.9
5193842026-07-17NULLcompleted34.9
51941152026-07-19NULLcompleted79.9
5195742026-07-233completed33.8
5196922026-07-2712completed19.9
51971162026-07-2712completed27.9
51981172026-07-28NULLcompleted99.9
5199672026-07-303completed29.9
52001182026-08-03NULLcompleted119
52011192026-08-073completed102.8
52021202026-08-09NULLcompleted89.9
5203932026-08-153completed47.8
52041212026-08-15NULLcompleted27.9
52051222026-08-18NULLcompleted44.9
52061022026-08-243completed89.8
52071232026-08-2512completed142.7
52081242026-08-2712completed113.7
5209952026-08-2812completed99.9
5210922026-08-313completed29.8
52111252026-08-313completed19.9
52121102026-09-01NULLcompleted42.7
52131262026-09-033completed29.9
52141272026-09-07NULLcompleted29.8
52151282026-09-13NULLcompleted24.9
52161292026-09-1913completed89.9
52171302026-09-20NULLcompleted19.9
52181172026-09-213completed96.8
52191312026-09-223completed89.9
5220502026-09-23NULLcompleted44.9
5221912026-09-23NULLcompleted89.9
5222922026-09-233completed89.9
52231322026-09-2612completed89.9
52241152026-10-03NULLcompleted25.8
52251332026-10-0413cancelled49.9
5226632026-10-05NULLcompleted24.9
52271342026-10-0513completed27.9
52281062026-10-08NULLcompleted29.9
52291192026-10-08NULLcompleted24.9
52301352026-10-1012completed24.9
5231952026-10-13NULLcompleted24.9
52321022026-10-13NULLcompleted49.9
5233982026-10-14NULLcompleted14.9
52341362026-10-164completed24.9
52351372026-10-203completed34.9
52361382026-10-2213completed34.9
52371392026-10-27NULLcompleted89.8
52381402026-10-293completed19.9
52391122026-10-31NULLcompleted104.8
campaigns 14 rows, 6 columns
campaign_idnamechannelstart_dateend_datecost
1Paid search H1 2025Paid Search2025-01-012025-06-30120
2Paid social spring 2025Paid Social2025-03-012025-05-31160
3Email newsletter (ongoing)Email2025-01-012026-12-31360
4Affiliate program sports blogsAffiliate2025-01-012026-12-31240
5Paid search H2 2025Paid Search2025-07-012025-12-31420
6Paid social summer 2025Paid Social2025-06-152025-08-31180
7Email Black Friday week 2025Email2025-11-242025-12-0140
8Paid social Black Friday week 2025Paid Social2025-11-202025-12-01230
9Paid search H1 2026Paid Search2026-01-012026-06-30450
10Paid social fitness January 2026Paid Social2026-01-022026-01-31150
11Email spring sale 2026Email2026-03-022026-03-3140
12Paid search H2 2026Paid Search2026-07-012026-12-31380
13Paid social Sep/Oct 2026Paid Social2026-09-152026-10-31220
14Paid social video testPaid Social2026-05-042026-05-24120

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

17. Finding short payment terms

Basic · Dates · Filtering · Finance

Task Accounts is checking special terms. Show every invoice whose payment term is shorter than 30 days (days from invoice_date to due_date): invoice_id, customer and term_days (as a whole number), sorted by invoice_id.

invoices 60 rows, 5 columns
invoice_idcustomerinvoice_datedue_dateamount
26001Northgate Cycles Ltd2026-01-032026-02-0226959.83
26002Riverside Bike Co.2026-01-062026-02-0514721.94
26003Hillcrest Cycle Shop2026-01-082026-02-0716992.65
26004Pedal Point Inc.2026-01-122026-02-1123417.22
26005Urban Wheels Online2026-01-152026-03-1628124.62
26006Summit Outdoor Supply2026-01-172026-02-1620273.54
26007Coastline Cycles2026-01-212026-02-2012687.37
26008Greenway Bikes2026-01-232026-02-2211730.56
26009Two Wheel Depot2026-01-262026-02-2519622.5
26010Maple Street Cycles2026-01-292026-02-1215772.49
26011Northgate Cycles Ltd2026-02-032026-03-0534472.71
26012Riverside Bike Co.2026-02-052026-03-0721466.08
26013Hillcrest Cycle Shop2026-02-092026-03-1120975.08
26014Pedal Point Inc.2026-02-122026-03-1430082.56
26015Urban Wheels Online2026-02-142026-04-1540785.91
26016Summit Outdoor Supply2026-02-182026-03-2024787.09
26017Coastline Cycles2026-02-212026-03-2316231.53
26018Greenway Bikes2026-02-242026-03-2614692.65
26019Two Wheel Depot2026-02-262026-03-2826205.7
26020Maple Street Cycles2026-02-262026-03-1219640.44
26021Northgate Cycles Ltd2026-03-032026-04-0254429.19
26022Riverside Bike Co.2026-03-062026-04-0532466.62
26023Hillcrest Cycle Shop2026-03-082026-04-0734701.33
26024Pedal Point Inc.2026-03-112026-04-1052082.83
26025Urban Wheels Online2026-03-142026-05-1359991.26
26026Summit Outdoor Supply2026-03-172026-04-1637796.33
26027Coastline Cycles2026-03-202026-04-1924397.37
26028Greenway Bikes2026-03-232026-04-2221785.83
26029Two Wheel Depot2026-03-272026-04-2639812.27
26030Maple Street Cycles2026-03-292026-04-1218452.9
26031Northgate Cycles Ltd2026-04-022026-05-0259320
26032Riverside Bike Co.2026-04-062026-05-0637402.19
26033Hillcrest Cycle Shop2026-04-082026-05-0842329.35
26034Pedal Point Inc.2026-04-112026-05-1161184.01
26035Urban Wheels Online2026-04-142026-06-1375122.1
26036Summit Outdoor Supply2026-04-182026-05-1842952.05
26037Coastline Cycles2026-04-202026-05-2029968.46
26038Greenway Bikes2026-04-242026-05-2425966.97
26039Two Wheel Depot2026-04-262026-05-2650138.68
26040Maple Street Cycles2026-04-282026-05-1227754.11
26041Northgate Cycles Ltd2026-05-032026-06-0265530.8
26042Riverside Bike Co.2026-05-062026-06-0537631.02
26043Hillcrest Cycle Shop2026-05-082026-06-0741637.92
26044Pedal Point Inc.2026-05-112026-06-1057840.47
26045Urban Wheels Online2026-05-142026-07-1368239.27
26046Summit Outdoor Supply2026-05-172026-06-1644576.3
26047Coastline Cycles2026-05-212026-06-2028255.84
26048Greenway Bikes2026-05-242026-06-2325800.16
26049Two Wheel Depot2026-05-262026-06-2546653.8
26050Maple Street Cycles2026-05-292026-06-1221711
26051Northgate Cycles Ltd2026-06-032026-07-0348415.21
26052Riverside Bike Co.2026-06-062026-07-0627191.07
26053Hillcrest Cycle Shop2026-06-092026-07-0932156.21
26054Pedal Point Inc.2026-06-122026-07-1246139.99
26055Urban Wheels Online2026-06-302026-08-2955652
26056Summit Outdoor Supply2026-06-172026-07-1737295.37
26057Coastline Cycles2026-06-202026-07-2026031.62
26058Greenway Bikes2026-06-232026-07-2321187.55
26059Two Wheel Depot2026-06-272026-07-2741200.86
26060Maple Street Cycles2026-06-282026-07-1214292.64

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

What these questions have in common

  • Check the grain first: what is one row of the table, an order or an order line? That decides whether COUNT(*) or COUNT(DISTINCT ...) is right.
  • Think about NULL: a condition with <> or = loses rows with NULL, and COUNT(column) skips them. Interviewers notice when you bring this up yourself.
  • Dates as text: SQLite stores dates as YYYY-MM-DD text. Comparing works directly, calculating only with date() or julianday().
  • Percentages need a decimal: 100.0 instead of 100, or the database cuts off the decimals.

FAQ

What do I need to know for the basic questions?

SELECT with WHERE, ORDER BY, GROUP BY with HAVING, CASE, the main text and date functions and a simple JOIN. That's levels 1 to 3 of the SQL course.

Why doesn't my query count even though the result looks the same?

Usually because of the variant: the check runs a second time on changed data. If a value is typed into the query or a condition is missing that happens not to matter for the visible data, it shows up there. The message tells you what to look for.

Can I use different functions from the model answer?

Yes. The result is checked, not the text. NOT EXISTS instead of LEFT JOIN, BETWEEN instead of two comparisons: if the rows and values match, the question is solved.

Next: intermediate questions

Window functions, CTEs, self joins and deleting duplicates.

Intermediate questions All 50 questions

Write to us

Choose language

Select your preferred language