Advanced SQL interview questions
Questions 35 to 50 from SQL 50. They combine several techniques in one query and are the kind of question data analysis and finance teams use to test experienced candidates.
In short: advanced interview questions are rarely about one function you need to know. They are three or four steps in CTEs, and each step has its own trap: gaps and islands, a time window in days rather than rows, a cohort whose period isn't over yet.
How practice works here
Write the query step by step: write the first CTE, run it, look at the result, then add the next. That way you catch mistakes before they spread through three levels. The check compares the final result with the model answer, on hidden data too.
The stopwatch above each question lets you test yourself under time pressure. It remembers your best time only in your browser and has no effect on points. The first question on this page is free, the rest are part of Premium.
The 16 questions
35. Median order value
Task The average order value is skewed by a few large orders. Calculate the median of amount across all orders that aren't cancelled: the value in the middle of the sorted list, or for an even count the average of the two middle values. Show a single number, median, rounded to 2 decimal places. SQLite has no built-in function for it.
orders 122 rows, 5 columns
| order_id | customer_id | order_date | status | amount |
|---|---|---|---|---|
| 5001 | 2 | 2025-11-01 | cancelled | 93.9 |
| 5002 | 4 | 2025-11-02 | delivered | 238.8 |
| 5003 | 6 | 2025-11-08 | delivered | 14.9 |
| 5004 | 3 | 2025-11-10 | delivered | 29.9 |
| 5005 | 7 | 2025-11-11 | delivered | 44.9 |
| 5006 | 5 | 2025-11-13 | delivered | 104.7 |
| 5007 | 11 | 2025-11-16 | delivered | 17.9 |
| 5008 | 13 | 2025-11-17 | delivered | 119 |
| 5009 | 9 | 2025-11-18 | delivered | 206.8 |
| 5010 | 10 | 2025-11-20 | delivered | 758 |
| 5011 | 12 | 2025-11-23 | delivered | 44.9 |
| 5012 | 1 | 2025-11-25 | delivered | 77.8 |
| 5013 | 4 | 2025-11-27 | delivered | 149 |
| 5014 | 8 | 2025-11-28 | delivered | 39.9 |
| 5015 | 10 | 2025-12-15 | delivered | 777.9 |
| 5016 | 14 | 2025-12-16 | delivered | 55.8 |
| 5017 | 2 | 2025-12-22 | delivered | 34.9 |
| 5018 | 16 | 2025-12-22 | delivered | 79 |
| 5019 | 15 | 2025-12-29 | delivered | 22.9 |
| 5020 | 20 | 2025-12-29 | delivered | 59.8 |
| 5021 | 21 | 2025-12-30 | delivered | 379 |
| 5022 | 19 | 2025-12-31 | delivered | 114.7 |
| 5023 | 17 | 2026-01-03 | delivered | 49.8 |
| 5024 | 18 | 2026-01-08 | delivered | 79 |
| 5025 | 6 | 2026-01-14 | delivered | 44.9 |
| 5026 | 11 | 2026-01-16 | delivered | 12.9 |
| 5027 | 9 | 2026-01-17 | delivered | 49.9 |
| 5028 | 2 | 2026-01-21 | delivered | 59.9 |
| 5029 | 22 | 2026-01-24 | delivered | 49.9 |
| 5030 | 24 | 2026-01-25 | delivered | 498 |
| 5031 | 25 | 2026-02-04 | delivered | 413.9 |
| 5032 | 5 | 2026-02-05 | delivered | 34.9 |
| 5033 | 28 | 2026-02-06 | cancelled | 34.9 |
| 5034 | 26 | 2026-02-11 | delivered | 17.9 |
| 5035 | 11 | 2026-02-20 | delivered | 39.9 |
| 5036 | 21 | 2026-02-23 | delivered | 170.9 |
| 5037 | 29 | 2026-02-25 | delivered | 49.9 |
| 5038 | 27 | 2026-02-26 | delivered | 24.9 |
| 5039 | 12 | 2026-03-03 | delivered | 308 |
| 5040 | 18 | 2026-03-03 | delivered | 26.9 |
| 5041 | 15 | 2026-03-06 | delivered | 99.6 |
| 5042 | 1 | 2026-03-07 | delivered | 403.8 |
| 5043 | 31 | 2026-03-11 | delivered | 417.7 |
| 5044 | 30 | 2026-03-12 | delivered | 149 |
| 5045 | 33 | 2026-03-13 | delivered | 158 |
| 5046 | 34 | 2026-03-19 | delivered | 189 |
| 5047 | 32 | 2026-03-27 | delivered | 123.8 |
| 5048 | 35 | 2026-03-30 | delivered | 93.9 |
| 5049 | 19 | 2026-04-01 | delivered | 69.8 |
| 5050 | 2 | 2026-04-04 | cancelled | 368.9 |
| 5051 | 34 | 2026-04-06 | delivered | 47.8 |
| 5052 | 20 | 2026-04-16 | delivered | 119 |
| 5053 | 6 | 2026-04-22 | delivered | 258.7 |
| 5054 | 2 | 2026-04-23 | cancelled | 126.7 |
| 5055 | 11 | 2026-04-24 | delivered | 29.9 |
| 5056 | 36 | 2026-04-26 | delivered | 79 |
| 5057 | 37 | 2026-04-26 | cancelled | 12.9 |
| 5058 | 39 | 2026-04-27 | delivered | 117.7 |
| 5059 | 38 | 2026-04-29 | delivered | 19.9 |
| 5060 | 22 | 2026-04-30 | delivered | 59.9 |
| 5061 | 99 | 2026-05-01 | delivered | 63.7 |
| 5062 | 40 | 2026-05-04 | delivered | 158 |
| 5063 | 41 | 2026-05-05 | delivered | 378 |
| 5064 | 29 | 2026-05-14 | delivered | 228.7 |
| 5065 | 43 | 2026-05-17 | delivered | 74.7 |
| 5066 | 45 | 2026-05-25 | cancelled | 39.9 |
| 5067 | 44 | 2026-05-27 | delivered | 69.8 |
| 5068 | 46 | 2026-05-31 | delivered | 80.7 |
| 5069 | 27 | 2026-06-04 | delivered | 97.7 |
| 5070 | 31 | 2026-06-09 | delivered | 68.7 |
| 5071 | 18 | 2026-06-10 | delivered | 189 |
| 5072 | 19 | 2026-06-11 | delivered | 57.7 |
| 5073 | 35 | 2026-06-13 | delivered | 149 |
| 5074 | 47 | 2026-06-19 | delivered | 119 |
| 5075 | 49 | 2026-06-20 | delivered | 39.9 |
| 5076 | 48 | 2026-06-23 | delivered | 49.9 |
| 5077 | 42 | 2026-06-25 | delivered | 19.9 |
| 5078 | 51 | 2026-06-27 | delivered | 34.9 |
| 5079 | 39 | 2026-07-01 | delivered | 59.7 |
| 5080 | 50 | 2026-07-01 | delivered | 25.8 |
| 5081 | 45 | 2026-07-02 | delivered | 188.8 |
| 5082 | 19 | 2026-07-04 | delivered | 134.4 |
| 5083 | 53 | 2026-07-12 | delivered | 83.7 |
| 5084 | 52 | 2026-07-14 | delivered | 77.8 |
| 5085 | 38 | 2026-07-15 | delivered | 129.7 |
| 5086 | 54 | 2026-07-15 | delivered | 418.8 |
| 5087 | 46 | 2026-07-17 | delivered | 59.8 |
| 5088 | 29 | 2026-07-19 | delivered | 188.9 |
| 5089 | 36 | 2026-07-19 | delivered | 124.7 |
| 5090 | 45 | 2026-07-27 | delivered | 14.9 |
| 5091 | 41 | 2026-07-29 | delivered | 19.9 |
| 5092 | 58 | 2026-08-01 | delivered | 99.8 |
| 5093 | 56 | 2026-08-05 | delivered | 74.7 |
| 5094 | 53 | 2026-08-06 | delivered | 98.9 |
| 5095 | 59 | 2026-08-07 | delivered | 22.9 |
| 5096 | 18 | 2026-08-12 | delivered | 1157 |
| 5097 | 61 | 2026-08-16 | delivered | 44.7 |
| 5098 | 29 | 2026-08-20 | delivered | 105.7 |
| 5099 | 60 | 2026-08-24 | delivered | 307 |
| 5100 | 39 | 2026-08-27 | delivered | 103.9 |
| 5101 | 44 | 2026-08-28 | delivered | 243.8 |
| 5102 | 31 | 2026-08-31 | delivered | 128.9 |
| 5103 | 54 | 2026-08-31 | delivered | 298 |
| 5104 | 42 | 2026-09-01 | delivered | 388.9 |
| 5105 | 47 | 2026-09-01 | delivered | 124.7 |
| 5106 | 63 | 2026-09-06 | cancelled | 14.9 |
| 5107 | 64 | 2026-09-06 | delivered | 62.8 |
| 5108 | 65 | 2026-09-06 | cancelled | 208.6 |
| 5109 | 62 | 2026-09-11 | delivered | 34.9 |
| 5110 | 27 | 2026-09-18 | delivered | 29.9 |
| 5111 | 42 | 2026-09-20 | delivered | 104.7 |
| 5112 | 41 | 2026-09-21 | delivered | 24.9 |
| 5113 | 46 | 2026-09-27 | delivered | 94.6 |
| 5114 | 66 | 2026-09-28 | delivered | 29.9 |
| 5115 | 67 | 2026-10-01 | delivered | 34.9 |
| 5116 | 51 | 2026-10-07 | delivered | 69.8 |
| 5117 | 53 | 2026-10-07 | cancelled | 34.9 |
| 5118 | 70 | 2026-10-09 | delivered | 211.9 |
| 5119 | 64 | 2026-10-16 | delivered | 698 |
| 5120 | 68 | 2026-10-21 | delivered | 183.9 |
| 5121 | 69 | 2026-10-27 | shipped | 159.4 |
| 5122 | 27 | 2026-10-30 | shipped | 118.9 |
36. From which order is someone a regular?
Task In the loyalty programme, a customer becomes a regular once they have spent at least 300 in total (sum of amount of their orders that aren't cancelled, added up by date, and by order_id for the same date). For every customer who reached the threshold, show the order that took them to or past it: customer_id, order_id, order_date and running_total (the sum up to and including this order, 2 decimal places), sorted by order_date, then customer_id.
orders 122 rows, 5 columns
| order_id | customer_id | order_date | status | amount |
|---|---|---|---|---|
| 5001 | 2 | 2025-11-01 | cancelled | 93.9 |
| 5002 | 4 | 2025-11-02 | delivered | 238.8 |
| 5003 | 6 | 2025-11-08 | delivered | 14.9 |
| 5004 | 3 | 2025-11-10 | delivered | 29.9 |
| 5005 | 7 | 2025-11-11 | delivered | 44.9 |
| 5006 | 5 | 2025-11-13 | delivered | 104.7 |
| 5007 | 11 | 2025-11-16 | delivered | 17.9 |
| 5008 | 13 | 2025-11-17 | delivered | 119 |
| 5009 | 9 | 2025-11-18 | delivered | 206.8 |
| 5010 | 10 | 2025-11-20 | delivered | 758 |
| 5011 | 12 | 2025-11-23 | delivered | 44.9 |
| 5012 | 1 | 2025-11-25 | delivered | 77.8 |
| 5013 | 4 | 2025-11-27 | delivered | 149 |
| 5014 | 8 | 2025-11-28 | delivered | 39.9 |
| 5015 | 10 | 2025-12-15 | delivered | 777.9 |
| 5016 | 14 | 2025-12-16 | delivered | 55.8 |
| 5017 | 2 | 2025-12-22 | delivered | 34.9 |
| 5018 | 16 | 2025-12-22 | delivered | 79 |
| 5019 | 15 | 2025-12-29 | delivered | 22.9 |
| 5020 | 20 | 2025-12-29 | delivered | 59.8 |
| 5021 | 21 | 2025-12-30 | delivered | 379 |
| 5022 | 19 | 2025-12-31 | delivered | 114.7 |
| 5023 | 17 | 2026-01-03 | delivered | 49.8 |
| 5024 | 18 | 2026-01-08 | delivered | 79 |
| 5025 | 6 | 2026-01-14 | delivered | 44.9 |
| 5026 | 11 | 2026-01-16 | delivered | 12.9 |
| 5027 | 9 | 2026-01-17 | delivered | 49.9 |
| 5028 | 2 | 2026-01-21 | delivered | 59.9 |
| 5029 | 22 | 2026-01-24 | delivered | 49.9 |
| 5030 | 24 | 2026-01-25 | delivered | 498 |
| 5031 | 25 | 2026-02-04 | delivered | 413.9 |
| 5032 | 5 | 2026-02-05 | delivered | 34.9 |
| 5033 | 28 | 2026-02-06 | cancelled | 34.9 |
| 5034 | 26 | 2026-02-11 | delivered | 17.9 |
| 5035 | 11 | 2026-02-20 | delivered | 39.9 |
| 5036 | 21 | 2026-02-23 | delivered | 170.9 |
| 5037 | 29 | 2026-02-25 | delivered | 49.9 |
| 5038 | 27 | 2026-02-26 | delivered | 24.9 |
| 5039 | 12 | 2026-03-03 | delivered | 308 |
| 5040 | 18 | 2026-03-03 | delivered | 26.9 |
| 5041 | 15 | 2026-03-06 | delivered | 99.6 |
| 5042 | 1 | 2026-03-07 | delivered | 403.8 |
| 5043 | 31 | 2026-03-11 | delivered | 417.7 |
| 5044 | 30 | 2026-03-12 | delivered | 149 |
| 5045 | 33 | 2026-03-13 | delivered | 158 |
| 5046 | 34 | 2026-03-19 | delivered | 189 |
| 5047 | 32 | 2026-03-27 | delivered | 123.8 |
| 5048 | 35 | 2026-03-30 | delivered | 93.9 |
| 5049 | 19 | 2026-04-01 | delivered | 69.8 |
| 5050 | 2 | 2026-04-04 | cancelled | 368.9 |
| 5051 | 34 | 2026-04-06 | delivered | 47.8 |
| 5052 | 20 | 2026-04-16 | delivered | 119 |
| 5053 | 6 | 2026-04-22 | delivered | 258.7 |
| 5054 | 2 | 2026-04-23 | cancelled | 126.7 |
| 5055 | 11 | 2026-04-24 | delivered | 29.9 |
| 5056 | 36 | 2026-04-26 | delivered | 79 |
| 5057 | 37 | 2026-04-26 | cancelled | 12.9 |
| 5058 | 39 | 2026-04-27 | delivered | 117.7 |
| 5059 | 38 | 2026-04-29 | delivered | 19.9 |
| 5060 | 22 | 2026-04-30 | delivered | 59.9 |
| 5061 | 99 | 2026-05-01 | delivered | 63.7 |
| 5062 | 40 | 2026-05-04 | delivered | 158 |
| 5063 | 41 | 2026-05-05 | delivered | 378 |
| 5064 | 29 | 2026-05-14 | delivered | 228.7 |
| 5065 | 43 | 2026-05-17 | delivered | 74.7 |
| 5066 | 45 | 2026-05-25 | cancelled | 39.9 |
| 5067 | 44 | 2026-05-27 | delivered | 69.8 |
| 5068 | 46 | 2026-05-31 | delivered | 80.7 |
| 5069 | 27 | 2026-06-04 | delivered | 97.7 |
| 5070 | 31 | 2026-06-09 | delivered | 68.7 |
| 5071 | 18 | 2026-06-10 | delivered | 189 |
| 5072 | 19 | 2026-06-11 | delivered | 57.7 |
| 5073 | 35 | 2026-06-13 | delivered | 149 |
| 5074 | 47 | 2026-06-19 | delivered | 119 |
| 5075 | 49 | 2026-06-20 | delivered | 39.9 |
| 5076 | 48 | 2026-06-23 | delivered | 49.9 |
| 5077 | 42 | 2026-06-25 | delivered | 19.9 |
| 5078 | 51 | 2026-06-27 | delivered | 34.9 |
| 5079 | 39 | 2026-07-01 | delivered | 59.7 |
| 5080 | 50 | 2026-07-01 | delivered | 25.8 |
| 5081 | 45 | 2026-07-02 | delivered | 188.8 |
| 5082 | 19 | 2026-07-04 | delivered | 134.4 |
| 5083 | 53 | 2026-07-12 | delivered | 83.7 |
| 5084 | 52 | 2026-07-14 | delivered | 77.8 |
| 5085 | 38 | 2026-07-15 | delivered | 129.7 |
| 5086 | 54 | 2026-07-15 | delivered | 418.8 |
| 5087 | 46 | 2026-07-17 | delivered | 59.8 |
| 5088 | 29 | 2026-07-19 | delivered | 188.9 |
| 5089 | 36 | 2026-07-19 | delivered | 124.7 |
| 5090 | 45 | 2026-07-27 | delivered | 14.9 |
| 5091 | 41 | 2026-07-29 | delivered | 19.9 |
| 5092 | 58 | 2026-08-01 | delivered | 99.8 |
| 5093 | 56 | 2026-08-05 | delivered | 74.7 |
| 5094 | 53 | 2026-08-06 | delivered | 98.9 |
| 5095 | 59 | 2026-08-07 | delivered | 22.9 |
| 5096 | 18 | 2026-08-12 | delivered | 1157 |
| 5097 | 61 | 2026-08-16 | delivered | 44.7 |
| 5098 | 29 | 2026-08-20 | delivered | 105.7 |
| 5099 | 60 | 2026-08-24 | delivered | 307 |
| 5100 | 39 | 2026-08-27 | delivered | 103.9 |
| 5101 | 44 | 2026-08-28 | delivered | 243.8 |
| 5102 | 31 | 2026-08-31 | delivered | 128.9 |
| 5103 | 54 | 2026-08-31 | delivered | 298 |
| 5104 | 42 | 2026-09-01 | delivered | 388.9 |
| 5105 | 47 | 2026-09-01 | delivered | 124.7 |
| 5106 | 63 | 2026-09-06 | cancelled | 14.9 |
| 5107 | 64 | 2026-09-06 | delivered | 62.8 |
| 5108 | 65 | 2026-09-06 | cancelled | 208.6 |
| 5109 | 62 | 2026-09-11 | delivered | 34.9 |
| 5110 | 27 | 2026-09-18 | delivered | 29.9 |
| 5111 | 42 | 2026-09-20 | delivered | 104.7 |
| 5112 | 41 | 2026-09-21 | delivered | 24.9 |
| 5113 | 46 | 2026-09-27 | delivered | 94.6 |
| 5114 | 66 | 2026-09-28 | delivered | 29.9 |
| 5115 | 67 | 2026-10-01 | delivered | 34.9 |
| 5116 | 51 | 2026-10-07 | delivered | 69.8 |
| 5117 | 53 | 2026-10-07 | cancelled | 34.9 |
| 5118 | 70 | 2026-10-09 | delivered | 211.9 |
| 5119 | 64 | 2026-10-16 | delivered | 698 |
| 5120 | 68 | 2026-10-21 | delivered | 183.9 |
| 5121 | 69 | 2026-10-27 | shipped | 159.4 |
| 5122 | 27 | 2026-10-30 | shipped | 118.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.
37. Quarter-to-quarter retention
Task How many of a quarter's active customers buy again in the next quarter? A customer is active in a quarter if they have at least one completed order in it. For every quarter from the second one in the data, show quarter ('2025-Q2'), active_prev (active customers in the quarter before), retained (those also active in this quarter) and retention_pct (retained divided by active_prev times 100, 1 decimal place), sorted by quarter.
orders 239 rows, 6 columns
| order_id | customer_id | order_date | campaign_id | status | amount |
|---|---|---|---|---|---|
| 5001 | 1 | 2025-01-16 | 1 | completed | 29.8 |
| 5002 | 2 | 2025-01-24 | NULL | completed | 139.7 |
| 5003 | 3 | 2025-01-28 | NULL | completed | 49.9 |
| 5004 | 4 | 2025-02-01 | 4 | completed | 69.8 |
| 5005 | 5 | 2025-02-07 | 3 | completed | 89.9 |
| 5006 | 6 | 2025-02-14 | NULL | completed | 24.9 |
| 5007 | 7 | 2025-02-25 | NULL | cancelled | 24.9 |
| 5008 | 8 | 2025-03-03 | 2 | completed | 139.7 |
| 5009 | 9 | 2025-03-06 | 2 | completed | 34.9 |
| 5010 | 6 | 2025-03-13 | NULL | completed | 24.9 |
| 5011 | 10 | 2025-03-15 | 2 | completed | 19.9 |
| 5012 | 11 | 2025-03-17 | NULL | completed | 49.9 |
| 5013 | 12 | 2025-03-29 | 3 | cancelled | 89.9 |
| 5014 | 13 | 2025-03-30 | 4 | completed | 24.9 |
| 5015 | 2 | 2025-04-03 | 3 | completed | 24.9 |
| 5016 | 14 | 2025-04-05 | 4 | completed | 79.9 |
| 5017 | 5 | 2025-04-06 | 3 | completed | 34.9 |
| 5018 | 10 | 2025-04-10 | NULL | completed | 89.9 |
| 5019 | 15 | 2025-04-12 | 3 | completed | 114.8 |
| 5020 | 16 | 2025-04-19 | 3 | completed | 99.9 |
| 5021 | 17 | 2025-04-26 | NULL | cancelled | 79.9 |
| 5022 | 7 | 2025-04-30 | NULL | completed | 29.9 |
| 5023 | 18 | 2025-05-03 | NULL | completed | 34.9 |
| 5024 | 19 | 2025-05-08 | NULL | completed | 89.9 |
| 5025 | 20 | 2025-05-12 | 3 | completed | 19.9 |
| 5026 | 21 | 2025-05-17 | 2 | cancelled | 39.9 |
| 5027 | 22 | 2025-05-18 | NULL | completed | 79.9 |
| 5028 | 14 | 2025-05-24 | 1 | completed | 89.9 |
| 5029 | 23 | 2025-05-25 | 1 | completed | 29.8 |
| 5030 | 16 | 2025-06-01 | 3 | cancelled | 27.9 |
| 5031 | 24 | 2025-06-01 | NULL | completed | 19.9 |
| 5032 | 25 | 2025-06-09 | 3 | completed | 79.9 |
| 5033 | 26 | 2025-06-15 | 6 | cancelled | 34.9 |
| 5034 | 27 | 2025-06-16 | 3 | completed | 24.9 |
| 5035 | 28 | 2025-06-18 | 6 | completed | 29.8 |
| 5036 | 29 | 2025-06-25 | 6 | completed | 19.9 |
| 5037 | 30 | 2025-07-06 | NULL | completed | 19.8 |
| 5038 | 31 | 2025-07-08 | 5 | completed | 24.9 |
| 5039 | 32 | 2025-07-10 | 5 | completed | 119.7 |
| 5040 | 33 | 2025-07-14 | 6 | completed | 49.9 |
| 5041 | 34 | 2025-07-24 | 6 | completed | 34.9 |
| 5042 | 35 | 2025-07-28 | 6 | cancelled | 89.9 |
| 5043 | 24 | 2025-07-29 | 3 | completed | 34.9 |
| 5044 | 36 | 2025-08-01 | 6 | completed | 104.8 |
| 5045 | 5 | 2025-08-05 | 3 | completed | 29.9 |
| 5046 | 37 | 2025-08-06 | NULL | cancelled | 119 |
| 5047 | 2 | 2025-08-07 | 3 | completed | 89.9 |
| 5048 | 38 | 2025-08-09 | NULL | completed | 9.9 |
| 5049 | 39 | 2025-08-14 | 6 | completed | 19.9 |
| 5050 | 40 | 2025-08-19 | 4 | completed | 89.9 |
| 5051 | 41 | 2025-08-29 | NULL | completed | 89.9 |
| 5052 | 42 | 2025-08-29 | 3 | completed | 12.9 |
| 5053 | 43 | 2025-09-03 | NULL | completed | 24.9 |
| 5054 | 44 | 2025-09-06 | 5 | completed | 34.9 |
| 5055 | 23 | 2025-09-07 | 5 | completed | 99.9 |
| 5056 | 38 | 2025-09-12 | 3 | completed | 25.8 |
| 5057 | 45 | 2025-09-15 | NULL | completed | 19.9 |
| 5058 | 46 | 2025-09-18 | 5 | completed | 99.9 |
| 5059 | 41 | 2025-09-19 | NULL | completed | 34.9 |
| 5060 | 47 | 2025-09-19 | NULL | completed | 9.9 |
| 5061 | 5 | 2025-09-24 | NULL | completed | 24.9 |
| 5062 | 48 | 2025-09-29 | NULL | completed | 79.9 |
| 5063 | 49 | 2025-09-29 | 5 | completed | 29.9 |
| 5064 | 50 | 2025-10-08 | NULL | completed | 129 |
| 5065 | 14 | 2025-10-10 | NULL | completed | 86.7 |
| 5066 | 51 | 2025-10-11 | 5 | completed | 119.7 |
| 5067 | 16 | 2025-10-12 | 5 | completed | 99.9 |
| 5068 | 52 | 2025-10-14 | 5 | completed | 119.7 |
| 5069 | 34 | 2025-10-19 | NULL | completed | 54.8 |
| 5070 | 21 | 2025-10-20 | NULL | completed | 49.9 |
| 5071 | 42 | 2025-10-20 | 5 | completed | 16.9 |
| 5072 | 53 | 2025-10-21 | 3 | completed | 89.9 |
| 5073 | 54 | 2025-10-24 | NULL | completed | 54.8 |
| 5074 | 55 | 2025-10-29 | 5 | completed | 99.9 |
| 5075 | 56 | 2025-11-04 | NULL | completed | 34.9 |
| 5076 | 57 | 2025-11-05 | 5 | completed | 114.8 |
| 5077 | 27 | 2025-11-07 | 3 | completed | 12.9 |
| 5078 | 31 | 2025-11-07 | NULL | completed | 59.9 |
| 5079 | 32 | 2025-11-07 | NULL | completed | 27.9 |
| 5080 | 58 | 2025-11-18 | NULL | completed | 19.9 |
| 5081 | 59 | 2025-11-23 | 5 | completed | 89.9 |
| 5082 | 60 | 2025-11-23 | 8 | completed | 25.8 |
| 5083 | 12 | 2025-11-24 | 7 | completed | 47.92 |
| 5084 | 15 | 2025-11-24 | 8 | completed | 91.84 |
| 5085 | 48 | 2025-11-24 | 7 | completed | 55.76 |
| 5086 | 51 | 2025-11-24 | 7 | completed | 23.92 |
| 5087 | 1 | 2025-11-25 | 7 | completed | 31.92 |
| 5088 | 7 | 2025-11-25 | NULL | completed | 47.92 |
| 5089 | 61 | 2025-11-25 | 3 | completed | 23.92 |
| 5090 | 6 | 2025-11-26 | 7 | completed | 39.92 |
| 5091 | 31 | 2025-11-26 | 8 | completed | 23.92 |
| 5092 | 56 | 2025-11-26 | 8 | completed | 10.32 |
| 5093 | 13 | 2025-11-27 | 7 | cancelled | 91.84 |
| 5094 | 30 | 2025-11-27 | 7 | completed | 31.92 |
| 5095 | 38 | 2025-11-28 | 7 | completed | 103.2 |
| 5096 | 55 | 2025-11-28 | 8 | completed | 63.92 |
| 5097 | 9 | 2025-11-29 | 8 | completed | 27.92 |
| 5098 | 5 | 2025-11-30 | 8 | completed | 15.84 |
| 5099 | 42 | 2025-11-30 | 3 | completed | 7.92 |
| 5100 | 44 | 2025-11-30 | 7 | completed | 48.56 |
| 5101 | 46 | 2025-11-30 | 7 | completed | 38.24 |
| 5102 | 47 | 2025-11-30 | 7 | completed | 31.92 |
| 5103 | 24 | 2025-12-01 | 7 | completed | 90.24 |
| 5104 | 62 | 2025-12-01 | 8 | completed | 15.92 |
| 5105 | 63 | 2025-12-08 | NULL | completed | 19.8 |
| 5106 | 64 | 2025-12-11 | NULL | completed | 114.8 |
| 5107 | 14 | 2025-12-12 | NULL | completed | 29.9 |
| 5108 | 65 | 2025-12-15 | 5 | completed | 89.7 |
| 5109 | 66 | 2025-12-19 | 5 | completed | 104.8 |
| 5110 | 67 | 2025-12-25 | NULL | completed | 34.9 |
| 5111 | 68 | 2025-12-26 | NULL | completed | 59.9 |
| 5112 | 42 | 2026-01-04 | NULL | completed | 79.9 |
| 5113 | 69 | 2026-01-06 | 10 | completed | 16.9 |
| 5114 | 70 | 2026-01-06 | 3 | completed | 19.9 |
| 5115 | 2 | 2026-01-09 | 9 | completed | 89.9 |
| 5116 | 71 | 2026-01-16 | 9 | completed | 25.8 |
| 5117 | 72 | 2026-01-17 | 9 | completed | 89.9 |
| 5118 | 50 | 2026-01-18 | NULL | completed | 19.9 |
| 5119 | 73 | 2026-01-23 | 10 | completed | 59.9 |
| 5120 | 74 | 2026-01-26 | NULL | completed | 19.8 |
| 5121 | 75 | 2026-02-02 | 9 | completed | 119 |
| 5122 | 76 | 2026-02-06 | 4 | completed | 24.9 |
| 5123 | 77 | 2026-02-07 | NULL | completed | 79.9 |
| 5124 | 78 | 2026-02-13 | NULL | completed | 9.9 |
| 5125 | 79 | 2026-02-15 | NULL | completed | 104.8 |
| 5126 | 74 | 2026-02-18 | NULL | completed | 49.9 |
| 5127 | 80 | 2026-02-20 | 4 | completed | 19.9 |
| 5128 | 68 | 2026-02-24 | NULL | completed | 12.9 |
| 5129 | 81 | 2026-02-25 | 9 | completed | 29.9 |
| 5130 | 52 | 2026-02-28 | NULL | completed | 59.9 |
| 5131 | 38 | 2026-03-01 | 3 | completed | 89.9 |
| 5132 | 82 | 2026-03-01 | NULL | completed | 19.9 |
| 5133 | 4 | 2026-03-02 | NULL | completed | 29.8 |
| 5134 | 67 | 2026-03-03 | 11 | completed | 39.9 |
| 5135 | 2 | 2026-03-05 | 9 | completed | 44.9 |
| 5136 | 17 | 2026-03-05 | NULL | completed | 79.9 |
| 5137 | 31 | 2026-03-06 | NULL | completed | 136.7 |
| 5138 | 83 | 2026-03-07 | NULL | completed | 49.9 |
| 5139 | 70 | 2026-03-08 | 11 | completed | 47.8 |
| 5140 | 84 | 2026-03-11 | 3 | completed | 49.8 |
| 5141 | 7 | 2026-03-12 | NULL | completed | 19.9 |
| 5142 | 53 | 2026-03-12 | 11 | completed | 19.9 |
| 5143 | 85 | 2026-03-12 | 4 | completed | 22.8 |
| 5144 | 5 | 2026-03-13 | NULL | cancelled | 104.8 |
| 5145 | 16 | 2026-03-14 | 9 | completed | 34.9 |
| 5146 | 57 | 2026-03-15 | NULL | completed | 107.8 |
| 5147 | 14 | 2026-03-16 | 11 | completed | 24.9 |
| 5148 | 32 | 2026-03-16 | 11 | completed | 34.9 |
| 5149 | 54 | 2026-03-17 | NULL | completed | 34.9 |
| 5150 | 86 | 2026-03-17 | NULL | completed | 25.8 |
| 5151 | 27 | 2026-03-18 | NULL | completed | 9.9 |
| 5152 | 87 | 2026-03-19 | 9 | completed | 119 |
| 5153 | 72 | 2026-03-22 | 11 | completed | 24.9 |
| 5154 | 88 | 2026-04-01 | 4 | completed | 29.9 |
| 5155 | 89 | 2026-04-05 | 9 | completed | 49.9 |
| 5156 | 90 | 2026-04-05 | 9 | completed | 102.8 |
| 5157 | 74 | 2026-04-06 | 3 | completed | 24.9 |
| 5158 | 91 | 2026-04-11 | 9 | completed | 29.9 |
| 5159 | 61 | 2026-04-12 | NULL | completed | 79.9 |
| 5160 | 92 | 2026-04-14 | NULL | completed | 29.9 |
| 5161 | 93 | 2026-04-19 | NULL | completed | 29.9 |
| 5162 | 94 | 2026-04-24 | 9 | completed | 29.9 |
| 5163 | 95 | 2026-04-28 | 4 | completed | 44.9 |
| 5164 | 96 | 2026-04-30 | 9 | completed | 129 |
| 5165 | 92 | 2026-05-07 | NULL | completed | 55.7 |
| 5166 | 97 | 2026-05-10 | 4 | completed | 54.8 |
| 5167 | 98 | 2026-05-11 | 9 | completed | 14.9 |
| 5168 | 99 | 2026-05-13 | 4 | completed | 34.9 |
| 5169 | 100 | 2026-05-18 | 9 | completed | 129 |
| 5170 | 101 | 2026-05-19 | 4 | completed | 148.7 |
| 5171 | 63 | 2026-05-23 | 3 | cancelled | 24.9 |
| 5172 | 102 | 2026-05-25 | NULL | completed | 44.9 |
| 5173 | 78 | 2026-06-01 | NULL | cancelled | 153.9 |
| 5174 | 103 | 2026-06-01 | NULL | completed | 99.9 |
| 5175 | 42 | 2026-06-02 | 9 | completed | 129 |
| 5176 | 104 | 2026-06-04 | NULL | completed | 49.9 |
| 5177 | 105 | 2026-06-08 | NULL | completed | 19.9 |
| 5178 | 50 | 2026-06-09 | NULL | completed | 102.8 |
| 5179 | 106 | 2026-06-09 | NULL | completed | 119.7 |
| 5180 | 107 | 2026-06-16 | 4 | cancelled | 29.7 |
| 5181 | 108 | 2026-06-22 | 9 | completed | 12.9 |
| 5182 | 79 | 2026-06-23 | 3 | completed | 99.9 |
| 5183 | 109 | 2026-06-26 | 4 | completed | 129 |
| 5184 | 110 | 2026-06-26 | NULL | cancelled | 24.9 |
| 5185 | 81 | 2026-06-28 | NULL | completed | 99.9 |
| 5186 | 111 | 2026-07-02 | NULL | completed | 158.9 |
| 5187 | 77 | 2026-07-04 | NULL | completed | 114.7 |
| 5188 | 112 | 2026-07-04 | NULL | completed | 39.9 |
| 5189 | 113 | 2026-07-09 | 4 | cancelled | 19.9 |
| 5190 | 114 | 2026-07-14 | NULL | completed | 49.9 |
| 5191 | 83 | 2026-07-15 | NULL | completed | 148.7 |
| 5192 | 76 | 2026-07-17 | NULL | completed | 34.9 |
| 5193 | 84 | 2026-07-17 | NULL | completed | 34.9 |
| 5194 | 115 | 2026-07-19 | NULL | completed | 79.9 |
| 5195 | 74 | 2026-07-23 | 3 | completed | 33.8 |
| 5196 | 92 | 2026-07-27 | 12 | completed | 19.9 |
| 5197 | 116 | 2026-07-27 | 12 | completed | 27.9 |
| 5198 | 117 | 2026-07-28 | NULL | completed | 99.9 |
| 5199 | 67 | 2026-07-30 | 3 | completed | 29.9 |
| 5200 | 118 | 2026-08-03 | NULL | completed | 119 |
| 5201 | 119 | 2026-08-07 | 3 | completed | 102.8 |
| 5202 | 120 | 2026-08-09 | NULL | completed | 89.9 |
| 5203 | 93 | 2026-08-15 | 3 | completed | 47.8 |
| 5204 | 121 | 2026-08-15 | NULL | completed | 27.9 |
| 5205 | 122 | 2026-08-18 | NULL | completed | 44.9 |
| 5206 | 102 | 2026-08-24 | 3 | completed | 89.8 |
| 5207 | 123 | 2026-08-25 | 12 | completed | 142.7 |
| 5208 | 124 | 2026-08-27 | 12 | completed | 113.7 |
| 5209 | 95 | 2026-08-28 | 12 | completed | 99.9 |
| 5210 | 92 | 2026-08-31 | 3 | completed | 29.8 |
| 5211 | 125 | 2026-08-31 | 3 | completed | 19.9 |
| 5212 | 110 | 2026-09-01 | NULL | completed | 42.7 |
| 5213 | 126 | 2026-09-03 | 3 | completed | 29.9 |
| 5214 | 127 | 2026-09-07 | NULL | completed | 29.8 |
| 5215 | 128 | 2026-09-13 | NULL | completed | 24.9 |
| 5216 | 129 | 2026-09-19 | 13 | completed | 89.9 |
| 5217 | 130 | 2026-09-20 | NULL | completed | 19.9 |
| 5218 | 117 | 2026-09-21 | 3 | completed | 96.8 |
| 5219 | 131 | 2026-09-22 | 3 | completed | 89.9 |
| 5220 | 50 | 2026-09-23 | NULL | completed | 44.9 |
| 5221 | 91 | 2026-09-23 | NULL | completed | 89.9 |
| 5222 | 92 | 2026-09-23 | 3 | completed | 89.9 |
| 5223 | 132 | 2026-09-26 | 12 | completed | 89.9 |
| 5224 | 115 | 2026-10-03 | NULL | completed | 25.8 |
| 5225 | 133 | 2026-10-04 | 13 | cancelled | 49.9 |
| 5226 | 63 | 2026-10-05 | NULL | completed | 24.9 |
| 5227 | 134 | 2026-10-05 | 13 | completed | 27.9 |
| 5228 | 106 | 2026-10-08 | NULL | completed | 29.9 |
| 5229 | 119 | 2026-10-08 | NULL | completed | 24.9 |
| 5230 | 135 | 2026-10-10 | 12 | completed | 24.9 |
| 5231 | 95 | 2026-10-13 | NULL | completed | 24.9 |
| 5232 | 102 | 2026-10-13 | NULL | completed | 49.9 |
| 5233 | 98 | 2026-10-14 | NULL | completed | 14.9 |
| 5234 | 136 | 2026-10-16 | 4 | completed | 24.9 |
| 5235 | 137 | 2026-10-20 | 3 | completed | 34.9 |
| 5236 | 138 | 2026-10-22 | 13 | completed | 34.9 |
| 5237 | 139 | 2026-10-27 | NULL | completed | 89.8 |
| 5238 | 140 | 2026-10-29 | 3 | completed | 19.9 |
| 5239 | 112 | 2026-10-31 | NULL | completed | 104.8 |
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.
38. Session length by device
Task How long do visitors stay in the shop? A session's length is the time from its first to its last event (column event_time in events). Sessions with only one event have no measurable length and don't count. For each device, show sessions (sessions with at least two events) and avg_minutes (average length in minutes, 1 decimal place), sorted by device.
sessions 90 rows, 4 columns
| session_id | session_date | device | channel |
|---|---|---|---|
| 701 | 2026-10-01 | Mobile | Newsletter |
| 702 | 2026-10-01 | Desktop | Search |
| 703 | 2026-10-01 | Tablet | Newsletter |
| 704 | 2026-10-01 | Mobile | Newsletter |
| 705 | 2026-10-01 | Mobile | Social media |
| 706 | 2026-10-01 | Desktop | Referral |
| 707 | 2026-10-01 | Mobile | Social media |
| 708 | 2026-10-02 | Desktop | Search |
| 709 | 2026-10-02 | Desktop | Newsletter |
| 710 | 2026-10-02 | Mobile | Search |
| 711 | 2026-10-02 | Mobile | Search |
| 712 | 2026-10-02 | Desktop | Referral |
| 713 | 2026-10-02 | Desktop | Direct |
| 714 | 2026-10-03 | Mobile | Newsletter |
| 715 | 2026-10-03 | Tablet | Social media |
| 716 | 2026-10-03 | Desktop | Referral |
| 717 | 2026-10-03 | Desktop | Search |
| 718 | 2026-10-03 | Mobile | Social media |
| 719 | 2026-10-03 | Desktop | Social media |
| 720 | 2026-10-03 | Desktop | Social media |
| 721 | 2026-10-04 | Desktop | Social media |
| 722 | 2026-10-04 | Mobile | Search |
| 723 | 2026-10-04 | Desktop | Direct |
| 724 | 2026-10-04 | Desktop | Search |
| 725 | 2026-10-04 | Mobile | Direct |
| 726 | 2026-10-04 | Mobile | Referral |
| 727 | 2026-10-05 | Desktop | Search |
| 728 | 2026-10-05 | Desktop | Social media |
| 729 | 2026-10-05 | Mobile | Direct |
| 730 | 2026-10-05 | Mobile | Social media |
| 731 | 2026-10-05 | Mobile | Social media |
| 732 | 2026-10-05 | Mobile | Search |
| 733 | 2026-10-05 | Mobile | Social media |
| 734 | 2026-10-06 | Mobile | Search |
| 735 | 2026-10-06 | Desktop | Direct |
| 736 | 2026-10-06 | Desktop | Social media |
| 737 | 2026-10-06 | Desktop | Search |
| 738 | 2026-10-06 | Mobile | Direct |
| 739 | 2026-10-06 | Desktop | Search |
| 740 | 2026-10-07 | Mobile | Direct |
| 741 | 2026-10-07 | Mobile | Social media |
| 742 | 2026-10-07 | Mobile | Newsletter |
| 743 | 2026-10-07 | Mobile | Search |
| 744 | 2026-10-07 | Mobile | Newsletter |
| 745 | 2026-10-07 | Mobile | Search |
| 746 | 2026-10-08 | Tablet | Newsletter |
| 747 | 2026-10-08 | Desktop | Referral |
| 748 | 2026-10-08 | Desktop | Direct |
| 749 | 2026-10-08 | Tablet | Direct |
| 750 | 2026-10-08 | Desktop | Social media |
| 751 | 2026-10-08 | Mobile | Search |
| 752 | 2026-10-08 | Mobile | Direct |
| 753 | 2026-10-09 | Desktop | Newsletter |
| 754 | 2026-10-09 | Tablet | Social media |
| 755 | 2026-10-09 | Mobile | Social media |
| 756 | 2026-10-09 | Mobile | Search |
| 757 | 2026-10-09 | Mobile | Social media |
| 758 | 2026-10-09 | Mobile | Search |
| 759 | 2026-10-10 | Desktop | Search |
| 760 | 2026-10-10 | Desktop | Search |
| 761 | 2026-10-10 | Mobile | Direct |
| 762 | 2026-10-10 | Mobile | Social media |
| 763 | 2026-10-10 | Tablet | Social media |
| 764 | 2026-10-10 | Desktop | Search |
| 765 | 2026-10-10 | Mobile | Search |
| 766 | 2026-10-11 | Mobile | Search |
| 767 | 2026-10-11 | Desktop | Newsletter |
| 768 | 2026-10-11 | Mobile | Social media |
| 769 | 2026-10-11 | Desktop | Search |
| 770 | 2026-10-11 | Mobile | Search |
| 771 | 2026-10-11 | Tablet | Search |
| 772 | 2026-10-12 | Mobile | Social media |
| 773 | 2026-10-12 | Mobile | Search |
| 774 | 2026-10-12 | Desktop | Search |
| 775 | 2026-10-12 | Tablet | Search |
| 776 | 2026-10-12 | Desktop | Newsletter |
| 777 | 2026-10-12 | Mobile | Search |
| 778 | 2026-10-12 | Mobile | Search |
| 779 | 2026-10-13 | Mobile | Newsletter |
| 780 | 2026-10-13 | Desktop | Search |
| 781 | 2026-10-13 | Desktop | Direct |
| 782 | 2026-10-13 | Desktop | Search |
| 783 | 2026-10-13 | Mobile | Search |
| 784 | 2026-10-13 | Mobile | Search |
| 785 | 2026-10-14 | Tablet | Direct |
| 786 | 2026-10-14 | Mobile | Referral |
| 787 | 2026-10-14 | Mobile | Newsletter |
| 788 | 2026-10-14 | Mobile | Newsletter |
| 789 | 2026-10-14 | Mobile | Newsletter |
| 790 | 2026-10-14 | Desktop | Social media |
events 185 rows, 4 columns
| event_id | session_id | event_time | step |
|---|---|---|---|
| 1 | 702 | 2026-10-01 12:36:27 | Product page |
| 2 | 702 | 2026-10-01 12:37:11 | Cart |
| 3 | 703 | 2026-10-01 20:18:38 | Product page |
| 4 | 703 | 2026-10-01 20:21:39 | Cart |
| 5 | 703 | 2026-10-01 20:22:02 | Checkout |
| 6 | 703 | 2026-10-01 20:23:48 | Purchase |
| 7 | 704 | 2026-10-01 22:45:55 | Product page |
| 8 | 704 | 2026-10-01 22:49:50 | Product page |
| 9 | 704 | 2026-10-01 22:50:18 | Cart |
| 10 | 704 | 2026-10-01 22:54:12 | Checkout |
| 11 | 705 | 2026-10-01 18:53:28 | Product page |
| 12 | 706 | 2026-10-01 10:07:22 | Product page |
| 13 | 706 | 2026-10-01 10:09:26 | Cart |
| 14 | 707 | 2026-10-01 15:32:38 | Product page |
| 15 | 708 | 2026-10-02 08:35:46 | Product page |
| 16 | 708 | 2026-10-02 08:39:38 | Product page |
| 17 | 709 | 2026-10-02 09:25:13 | Product page |
| 18 | 709 | 2026-10-02 09:25:56 | Cart |
| 19 | 709 | 2026-10-02 09:28:37 | Checkout |
| 20 | 709 | 2026-10-02 09:29:33 | Purchase |
| 21 | 710 | 2026-10-02 07:08:53 | Product page |
| 22 | 711 | 2026-10-02 09:54:37 | Product page |
| 23 | 712 | 2026-10-02 09:50:30 | Product page |
| 24 | 713 | 2026-10-02 22:21:48 | Product page |
| 25 | 713 | 2026-10-02 22:23:20 | Product page |
| 26 | 713 | 2026-10-02 22:24:06 | Cart |
| 27 | 713 | 2026-10-02 22:25:01 | Checkout |
| 28 | 713 | 2026-10-02 22:27:37 | Purchase |
| 29 | 714 | 2026-10-03 09:46:44 | Product page |
| 30 | 714 | 2026-10-03 09:50:09 | Cart |
| 31 | 714 | 2026-10-03 09:53:27 | Checkout |
| 32 | 714 | 2026-10-03 09:54:59 | Purchase |
| 33 | 716 | 2026-10-03 22:50:52 | Product page |
| 34 | 717 | 2026-10-03 13:29:41 | Product page |
| 35 | 718 | 2026-10-03 14:52:58 | Product page |
| 36 | 719 | 2026-10-03 17:02:31 | Product page |
| 37 | 719 | 2026-10-03 17:04:16 | Cart |
| 38 | 721 | 2026-10-04 09:30:22 | Product page |
| 39 | 721 | 2026-10-04 09:32:27 | Cart |
| 40 | 722 | 2026-10-04 09:24:37 | Product page |
| 41 | 722 | 2026-10-04 09:25:11 | Product page |
| 42 | 722 | 2026-10-04 09:27:30 | Cart |
| 43 | 722 | 2026-10-04 09:28:21 | Checkout |
| 44 | 722 | 2026-10-04 09:31:45 | Purchase |
| 45 | 723 | 2026-10-04 22:35:29 | Product page |
| 46 | 724 | 2026-10-04 22:57:32 | Product page |
| 47 | 724 | 2026-10-04 22:59:57 | Product page |
| 48 | 724 | 2026-10-04 23:02:36 | Cart |
| 49 | 725 | 2026-10-04 13:10:38 | Product page |
| 50 | 725 | 2026-10-04 13:12:27 | Product page |
| 51 | 725 | 2026-10-04 13:15:22 | Cart |
| 52 | 725 | 2026-10-04 13:16:00 | Checkout |
| 53 | 726 | 2026-10-04 11:30:43 | Product page |
| 54 | 727 | 2026-10-05 22:24:38 | Product page |
| 55 | 728 | 2026-10-05 15:29:45 | Product page |
| 56 | 728 | 2026-10-05 15:30:59 | Product page |
| 57 | 729 | 2026-10-05 18:41:06 | Product page |
| 58 | 731 | 2026-10-05 22:07:22 | Product page |
| 59 | 731 | 2026-10-05 22:09:37 | Product page |
| 60 | 732 | 2026-10-05 18:10:56 | Product page |
| 61 | 732 | 2026-10-05 18:11:48 | Product page |
| 62 | 732 | 2026-10-05 18:15:32 | Cart |
| 63 | 732 | 2026-10-05 18:17:28 | Checkout |
| 64 | 732 | 2026-10-05 18:18:53 | Purchase |
| 65 | 733 | 2026-10-05 12:43:21 | Product page |
| 66 | 733 | 2026-10-05 12:46:03 | Cart |
| 67 | 733 | 2026-10-05 12:46:46 | Cart |
| 68 | 735 | 2026-10-06 11:27:54 | Product page |
| 69 | 735 | 2026-10-06 11:31:39 | Cart |
| 70 | 735 | 2026-10-06 11:32:17 | Checkout |
| 71 | 735 | 2026-10-06 11:35:28 | Purchase |
| 72 | 736 | 2026-10-06 09:13:36 | Product page |
| 73 | 737 | 2026-10-06 22:24:40 | Product page |
| 74 | 737 | 2026-10-06 22:27:23 | Product page |
| 75 | 738 | 2026-10-06 09:46:34 | Product page |
| 76 | 738 | 2026-10-06 09:50:10 | Product page |
| 77 | 739 | 2026-10-06 22:11:37 | Product page |
| 78 | 739 | 2026-10-06 22:13:18 | Cart |
| 79 | 739 | 2026-10-06 22:16:59 | Checkout |
| 80 | 739 | 2026-10-06 22:20:01 | Purchase |
| 81 | 740 | 2026-10-07 22:00:56 | Product page |
| 82 | 740 | 2026-10-07 22:02:43 | Product page |
| 83 | 740 | 2026-10-07 22:04:59 | Cart |
| 84 | 740 | 2026-10-07 22:07:10 | Checkout |
| 85 | 741 | 2026-10-07 12:49:24 | Product page |
| 86 | 742 | 2026-10-07 21:23:26 | Product page |
| 87 | 742 | 2026-10-07 21:26:04 | Product page |
| 88 | 742 | 2026-10-07 21:29:01 | Cart |
| 89 | 743 | 2026-10-07 14:53:04 | Product page |
| 90 | 743 | 2026-10-07 14:56:53 | Product page |
| 91 | 743 | 2026-10-07 14:57:55 | Cart |
| 92 | 744 | 2026-10-07 15:48:42 | Product page |
| 93 | 744 | 2026-10-07 15:51:57 | Product page |
| 94 | 746 | 2026-10-08 21:45:55 | Product page |
| 95 | 746 | 2026-10-08 21:47:17 | Cart |
| 96 | 747 | 2026-10-08 13:53:04 | Product page |
| 97 | 747 | 2026-10-08 13:56:49 | Cart |
| 98 | 747 | 2026-10-08 13:59:14 | Checkout |
| 99 | 748 | 2026-10-08 07:45:31 | Product page |
| 100 | 749 | 2026-10-08 16:38:24 | Product page |
| 101 | 749 | 2026-10-08 16:41:35 | Product page |
| 102 | 750 | 2026-10-08 21:42:19 | Product page |
| 103 | 750 | 2026-10-08 21:42:48 | Product page |
| 104 | 750 | 2026-10-08 21:46:17 | Cart |
| 105 | 750 | 2026-10-08 21:49:27 | Checkout |
| 106 | 751 | 2026-10-08 10:24:53 | Product page |
| 107 | 751 | 2026-10-08 10:27:16 | Product page |
| 108 | 752 | 2026-10-08 14:01:42 | Product page |
| 109 | 752 | 2026-10-08 14:03:31 | Product page |
| 110 | 753 | 2026-10-09 22:10:47 | Product page |
| 111 | 753 | 2026-10-09 22:13:43 | Product page |
| 112 | 753 | 2026-10-09 22:14:20 | Cart |
| 113 | 755 | 2026-10-09 22:20:17 | Product page |
| 114 | 755 | 2026-10-09 22:21:19 | Cart |
| 115 | 755 | 2026-10-09 22:22:23 | Checkout |
| 116 | 756 | 2026-10-09 09:42:32 | Product page |
| 117 | 756 | 2026-10-09 09:44:56 | Product page |
| 118 | 757 | 2026-10-09 13:17:31 | Product page |
| 119 | 757 | 2026-10-09 13:20:09 | Product page |
| 120 | 757 | 2026-10-09 13:21:15 | Cart |
| 121 | 757 | 2026-10-09 13:22:06 | Checkout |
| 122 | 759 | 2026-10-10 12:03:35 | Product page |
| 123 | 760 | 2026-10-10 17:33:33 | Product page |
| 124 | 760 | 2026-10-10 17:34:19 | Product page |
| 125 | 761 | 2026-10-10 19:44:54 | Product page |
| 126 | 761 | 2026-10-10 19:48:11 | Cart |
| 127 | 761 | 2026-10-10 19:49:10 | Checkout |
| 128 | 762 | 2026-10-10 20:53:29 | Product page |
| 129 | 762 | 2026-10-10 20:53:57 | Product page |
| 130 | 763 | 2026-10-10 14:27:38 | Product page |
| 131 | 764 | 2026-10-10 22:29:14 | Product page |
| 132 | 764 | 2026-10-10 22:32:55 | Product page |
| 133 | 764 | 2026-10-10 22:33:52 | Cart |
| 134 | 765 | 2026-10-10 13:03:20 | Product page |
| 135 | 765 | 2026-10-10 13:07:18 | Cart |
| 136 | 766 | 2026-10-11 19:36:58 | Product page |
| 137 | 767 | 2026-10-11 22:13:09 | Product page |
| 138 | 768 | 2026-10-11 15:06:24 | Product page |
| 139 | 768 | 2026-10-11 15:09:20 | Cart |
| 140 | 768 | 2026-10-11 15:11:08 | Checkout |
| 141 | 768 | 2026-10-11 15:12:36 | Purchase |
| 142 | 769 | 2026-10-11 19:06:55 | Product page |
| 143 | 769 | 2026-10-11 19:09:27 | Cart |
| 144 | 770 | 2026-10-11 13:02:38 | Product page |
| 145 | 771 | 2026-10-11 09:52:03 | Product page |
| 146 | 772 | 2026-10-12 10:33:46 | Product page |
| 147 | 773 | 2026-10-12 19:04:27 | Product page |
| 148 | 773 | 2026-10-12 19:07:36 | Cart |
| 149 | 773 | 2026-10-12 19:11:08 | Cart |
| 150 | 774 | 2026-10-12 21:19:50 | Product page |
| 151 | 775 | 2026-10-12 15:56:57 | Product page |
| 152 | 775 | 2026-10-12 15:59:54 | Cart |
| 153 | 775 | 2026-10-12 16:03:50 | Checkout |
| 154 | 775 | 2026-10-12 16:05:59 | Purchase |
| 155 | 776 | 2026-10-12 10:24:01 | Product page |
| 156 | 777 | 2026-10-12 10:27:35 | Product page |
| 157 | 779 | 2026-10-13 21:44:12 | Product page |
| 158 | 779 | 2026-10-13 21:47:55 | Cart |
| 159 | 779 | 2026-10-13 21:50:26 | Checkout |
| 160 | 779 | 2026-10-13 21:54:08 | Purchase |
| 161 | 780 | 2026-10-13 11:53:50 | Product page |
| 162 | 780 | 2026-10-13 11:55:49 | Product page |
| 163 | 780 | 2026-10-13 11:58:52 | Cart |
| 164 | 780 | 2026-10-13 12:02:28 | Checkout |
| 165 | 780 | 2026-10-13 12:03:37 | Purchase |
| 166 | 781 | 2026-10-13 08:25:15 | Product page |
| 167 | 782 | 2026-10-13 16:20:14 | Product page |
| 168 | 782 | 2026-10-13 16:22:04 | Product page |
| 169 | 782 | 2026-10-13 16:24:05 | Cart |
| 170 | 784 | 2026-10-13 17:20:03 | Product page |
| 171 | 784 | 2026-10-13 17:22:42 | Product page |
| 172 | 784 | 2026-10-13 17:23:43 | Cart |
| 173 | 785 | 2026-10-14 16:04:48 | Product page |
| 174 | 785 | 2026-10-14 16:08:41 | Product page |
| 175 | 786 | 2026-10-14 16:42:35 | Product page |
| 176 | 786 | 2026-10-14 16:45:44 | Product page |
| 177 | 786 | 2026-10-14 16:48:27 | Cart |
| 178 | 786 | 2026-10-14 16:50:28 | Checkout |
| 179 | 787 | 2026-10-14 17:36:26 | Product page |
| 180 | 787 | 2026-10-14 17:37:15 | Product page |
| 181 | 787 | 2026-10-14 17:39:38 | Cart |
| 182 | 787 | 2026-10-14 17:42:12 | Checkout |
| 183 | 787 | 2026-10-14 17:44:19 | Purchase |
| 184 | 789 | 2026-10-14 15:07:13 | Product page |
| 185 | 789 | 2026-10-14 15:08:32 | Cart |
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.
39. Growth versus the same month last year
Task Sporting goods sell seasonally, so management compares each month with the same month a year earlier. For January to October 2026, show per month (YYYY-MM) revenue, last_year (revenue in the same month of 2025) and growth_pct (change as a percentage, 1 decimal place). Revenue is the sum of amount over completed orders, rounded to 2 decimal places. Sorted by month.
orders 239 rows, 6 columns
| order_id | customer_id | order_date | campaign_id | status | amount |
|---|---|---|---|---|---|
| 5001 | 1 | 2025-01-16 | 1 | completed | 29.8 |
| 5002 | 2 | 2025-01-24 | NULL | completed | 139.7 |
| 5003 | 3 | 2025-01-28 | NULL | completed | 49.9 |
| 5004 | 4 | 2025-02-01 | 4 | completed | 69.8 |
| 5005 | 5 | 2025-02-07 | 3 | completed | 89.9 |
| 5006 | 6 | 2025-02-14 | NULL | completed | 24.9 |
| 5007 | 7 | 2025-02-25 | NULL | cancelled | 24.9 |
| 5008 | 8 | 2025-03-03 | 2 | completed | 139.7 |
| 5009 | 9 | 2025-03-06 | 2 | completed | 34.9 |
| 5010 | 6 | 2025-03-13 | NULL | completed | 24.9 |
| 5011 | 10 | 2025-03-15 | 2 | completed | 19.9 |
| 5012 | 11 | 2025-03-17 | NULL | completed | 49.9 |
| 5013 | 12 | 2025-03-29 | 3 | cancelled | 89.9 |
| 5014 | 13 | 2025-03-30 | 4 | completed | 24.9 |
| 5015 | 2 | 2025-04-03 | 3 | completed | 24.9 |
| 5016 | 14 | 2025-04-05 | 4 | completed | 79.9 |
| 5017 | 5 | 2025-04-06 | 3 | completed | 34.9 |
| 5018 | 10 | 2025-04-10 | NULL | completed | 89.9 |
| 5019 | 15 | 2025-04-12 | 3 | completed | 114.8 |
| 5020 | 16 | 2025-04-19 | 3 | completed | 99.9 |
| 5021 | 17 | 2025-04-26 | NULL | cancelled | 79.9 |
| 5022 | 7 | 2025-04-30 | NULL | completed | 29.9 |
| 5023 | 18 | 2025-05-03 | NULL | completed | 34.9 |
| 5024 | 19 | 2025-05-08 | NULL | completed | 89.9 |
| 5025 | 20 | 2025-05-12 | 3 | completed | 19.9 |
| 5026 | 21 | 2025-05-17 | 2 | cancelled | 39.9 |
| 5027 | 22 | 2025-05-18 | NULL | completed | 79.9 |
| 5028 | 14 | 2025-05-24 | 1 | completed | 89.9 |
| 5029 | 23 | 2025-05-25 | 1 | completed | 29.8 |
| 5030 | 16 | 2025-06-01 | 3 | cancelled | 27.9 |
| 5031 | 24 | 2025-06-01 | NULL | completed | 19.9 |
| 5032 | 25 | 2025-06-09 | 3 | completed | 79.9 |
| 5033 | 26 | 2025-06-15 | 6 | cancelled | 34.9 |
| 5034 | 27 | 2025-06-16 | 3 | completed | 24.9 |
| 5035 | 28 | 2025-06-18 | 6 | completed | 29.8 |
| 5036 | 29 | 2025-06-25 | 6 | completed | 19.9 |
| 5037 | 30 | 2025-07-06 | NULL | completed | 19.8 |
| 5038 | 31 | 2025-07-08 | 5 | completed | 24.9 |
| 5039 | 32 | 2025-07-10 | 5 | completed | 119.7 |
| 5040 | 33 | 2025-07-14 | 6 | completed | 49.9 |
| 5041 | 34 | 2025-07-24 | 6 | completed | 34.9 |
| 5042 | 35 | 2025-07-28 | 6 | cancelled | 89.9 |
| 5043 | 24 | 2025-07-29 | 3 | completed | 34.9 |
| 5044 | 36 | 2025-08-01 | 6 | completed | 104.8 |
| 5045 | 5 | 2025-08-05 | 3 | completed | 29.9 |
| 5046 | 37 | 2025-08-06 | NULL | cancelled | 119 |
| 5047 | 2 | 2025-08-07 | 3 | completed | 89.9 |
| 5048 | 38 | 2025-08-09 | NULL | completed | 9.9 |
| 5049 | 39 | 2025-08-14 | 6 | completed | 19.9 |
| 5050 | 40 | 2025-08-19 | 4 | completed | 89.9 |
| 5051 | 41 | 2025-08-29 | NULL | completed | 89.9 |
| 5052 | 42 | 2025-08-29 | 3 | completed | 12.9 |
| 5053 | 43 | 2025-09-03 | NULL | completed | 24.9 |
| 5054 | 44 | 2025-09-06 | 5 | completed | 34.9 |
| 5055 | 23 | 2025-09-07 | 5 | completed | 99.9 |
| 5056 | 38 | 2025-09-12 | 3 | completed | 25.8 |
| 5057 | 45 | 2025-09-15 | NULL | completed | 19.9 |
| 5058 | 46 | 2025-09-18 | 5 | completed | 99.9 |
| 5059 | 41 | 2025-09-19 | NULL | completed | 34.9 |
| 5060 | 47 | 2025-09-19 | NULL | completed | 9.9 |
| 5061 | 5 | 2025-09-24 | NULL | completed | 24.9 |
| 5062 | 48 | 2025-09-29 | NULL | completed | 79.9 |
| 5063 | 49 | 2025-09-29 | 5 | completed | 29.9 |
| 5064 | 50 | 2025-10-08 | NULL | completed | 129 |
| 5065 | 14 | 2025-10-10 | NULL | completed | 86.7 |
| 5066 | 51 | 2025-10-11 | 5 | completed | 119.7 |
| 5067 | 16 | 2025-10-12 | 5 | completed | 99.9 |
| 5068 | 52 | 2025-10-14 | 5 | completed | 119.7 |
| 5069 | 34 | 2025-10-19 | NULL | completed | 54.8 |
| 5070 | 21 | 2025-10-20 | NULL | completed | 49.9 |
| 5071 | 42 | 2025-10-20 | 5 | completed | 16.9 |
| 5072 | 53 | 2025-10-21 | 3 | completed | 89.9 |
| 5073 | 54 | 2025-10-24 | NULL | completed | 54.8 |
| 5074 | 55 | 2025-10-29 | 5 | completed | 99.9 |
| 5075 | 56 | 2025-11-04 | NULL | completed | 34.9 |
| 5076 | 57 | 2025-11-05 | 5 | completed | 114.8 |
| 5077 | 27 | 2025-11-07 | 3 | completed | 12.9 |
| 5078 | 31 | 2025-11-07 | NULL | completed | 59.9 |
| 5079 | 32 | 2025-11-07 | NULL | completed | 27.9 |
| 5080 | 58 | 2025-11-18 | NULL | completed | 19.9 |
| 5081 | 59 | 2025-11-23 | 5 | completed | 89.9 |
| 5082 | 60 | 2025-11-23 | 8 | completed | 25.8 |
| 5083 | 12 | 2025-11-24 | 7 | completed | 47.92 |
| 5084 | 15 | 2025-11-24 | 8 | completed | 91.84 |
| 5085 | 48 | 2025-11-24 | 7 | completed | 55.76 |
| 5086 | 51 | 2025-11-24 | 7 | completed | 23.92 |
| 5087 | 1 | 2025-11-25 | 7 | completed | 31.92 |
| 5088 | 7 | 2025-11-25 | NULL | completed | 47.92 |
| 5089 | 61 | 2025-11-25 | 3 | completed | 23.92 |
| 5090 | 6 | 2025-11-26 | 7 | completed | 39.92 |
| 5091 | 31 | 2025-11-26 | 8 | completed | 23.92 |
| 5092 | 56 | 2025-11-26 | 8 | completed | 10.32 |
| 5093 | 13 | 2025-11-27 | 7 | cancelled | 91.84 |
| 5094 | 30 | 2025-11-27 | 7 | completed | 31.92 |
| 5095 | 38 | 2025-11-28 | 7 | completed | 103.2 |
| 5096 | 55 | 2025-11-28 | 8 | completed | 63.92 |
| 5097 | 9 | 2025-11-29 | 8 | completed | 27.92 |
| 5098 | 5 | 2025-11-30 | 8 | completed | 15.84 |
| 5099 | 42 | 2025-11-30 | 3 | completed | 7.92 |
| 5100 | 44 | 2025-11-30 | 7 | completed | 48.56 |
| 5101 | 46 | 2025-11-30 | 7 | completed | 38.24 |
| 5102 | 47 | 2025-11-30 | 7 | completed | 31.92 |
| 5103 | 24 | 2025-12-01 | 7 | completed | 90.24 |
| 5104 | 62 | 2025-12-01 | 8 | completed | 15.92 |
| 5105 | 63 | 2025-12-08 | NULL | completed | 19.8 |
| 5106 | 64 | 2025-12-11 | NULL | completed | 114.8 |
| 5107 | 14 | 2025-12-12 | NULL | completed | 29.9 |
| 5108 | 65 | 2025-12-15 | 5 | completed | 89.7 |
| 5109 | 66 | 2025-12-19 | 5 | completed | 104.8 |
| 5110 | 67 | 2025-12-25 | NULL | completed | 34.9 |
| 5111 | 68 | 2025-12-26 | NULL | completed | 59.9 |
| 5112 | 42 | 2026-01-04 | NULL | completed | 79.9 |
| 5113 | 69 | 2026-01-06 | 10 | completed | 16.9 |
| 5114 | 70 | 2026-01-06 | 3 | completed | 19.9 |
| 5115 | 2 | 2026-01-09 | 9 | completed | 89.9 |
| 5116 | 71 | 2026-01-16 | 9 | completed | 25.8 |
| 5117 | 72 | 2026-01-17 | 9 | completed | 89.9 |
| 5118 | 50 | 2026-01-18 | NULL | completed | 19.9 |
| 5119 | 73 | 2026-01-23 | 10 | completed | 59.9 |
| 5120 | 74 | 2026-01-26 | NULL | completed | 19.8 |
| 5121 | 75 | 2026-02-02 | 9 | completed | 119 |
| 5122 | 76 | 2026-02-06 | 4 | completed | 24.9 |
| 5123 | 77 | 2026-02-07 | NULL | completed | 79.9 |
| 5124 | 78 | 2026-02-13 | NULL | completed | 9.9 |
| 5125 | 79 | 2026-02-15 | NULL | completed | 104.8 |
| 5126 | 74 | 2026-02-18 | NULL | completed | 49.9 |
| 5127 | 80 | 2026-02-20 | 4 | completed | 19.9 |
| 5128 | 68 | 2026-02-24 | NULL | completed | 12.9 |
| 5129 | 81 | 2026-02-25 | 9 | completed | 29.9 |
| 5130 | 52 | 2026-02-28 | NULL | completed | 59.9 |
| 5131 | 38 | 2026-03-01 | 3 | completed | 89.9 |
| 5132 | 82 | 2026-03-01 | NULL | completed | 19.9 |
| 5133 | 4 | 2026-03-02 | NULL | completed | 29.8 |
| 5134 | 67 | 2026-03-03 | 11 | completed | 39.9 |
| 5135 | 2 | 2026-03-05 | 9 | completed | 44.9 |
| 5136 | 17 | 2026-03-05 | NULL | completed | 79.9 |
| 5137 | 31 | 2026-03-06 | NULL | completed | 136.7 |
| 5138 | 83 | 2026-03-07 | NULL | completed | 49.9 |
| 5139 | 70 | 2026-03-08 | 11 | completed | 47.8 |
| 5140 | 84 | 2026-03-11 | 3 | completed | 49.8 |
| 5141 | 7 | 2026-03-12 | NULL | completed | 19.9 |
| 5142 | 53 | 2026-03-12 | 11 | completed | 19.9 |
| 5143 | 85 | 2026-03-12 | 4 | completed | 22.8 |
| 5144 | 5 | 2026-03-13 | NULL | cancelled | 104.8 |
| 5145 | 16 | 2026-03-14 | 9 | completed | 34.9 |
| 5146 | 57 | 2026-03-15 | NULL | completed | 107.8 |
| 5147 | 14 | 2026-03-16 | 11 | completed | 24.9 |
| 5148 | 32 | 2026-03-16 | 11 | completed | 34.9 |
| 5149 | 54 | 2026-03-17 | NULL | completed | 34.9 |
| 5150 | 86 | 2026-03-17 | NULL | completed | 25.8 |
| 5151 | 27 | 2026-03-18 | NULL | completed | 9.9 |
| 5152 | 87 | 2026-03-19 | 9 | completed | 119 |
| 5153 | 72 | 2026-03-22 | 11 | completed | 24.9 |
| 5154 | 88 | 2026-04-01 | 4 | completed | 29.9 |
| 5155 | 89 | 2026-04-05 | 9 | completed | 49.9 |
| 5156 | 90 | 2026-04-05 | 9 | completed | 102.8 |
| 5157 | 74 | 2026-04-06 | 3 | completed | 24.9 |
| 5158 | 91 | 2026-04-11 | 9 | completed | 29.9 |
| 5159 | 61 | 2026-04-12 | NULL | completed | 79.9 |
| 5160 | 92 | 2026-04-14 | NULL | completed | 29.9 |
| 5161 | 93 | 2026-04-19 | NULL | completed | 29.9 |
| 5162 | 94 | 2026-04-24 | 9 | completed | 29.9 |
| 5163 | 95 | 2026-04-28 | 4 | completed | 44.9 |
| 5164 | 96 | 2026-04-30 | 9 | completed | 129 |
| 5165 | 92 | 2026-05-07 | NULL | completed | 55.7 |
| 5166 | 97 | 2026-05-10 | 4 | completed | 54.8 |
| 5167 | 98 | 2026-05-11 | 9 | completed | 14.9 |
| 5168 | 99 | 2026-05-13 | 4 | completed | 34.9 |
| 5169 | 100 | 2026-05-18 | 9 | completed | 129 |
| 5170 | 101 | 2026-05-19 | 4 | completed | 148.7 |
| 5171 | 63 | 2026-05-23 | 3 | cancelled | 24.9 |
| 5172 | 102 | 2026-05-25 | NULL | completed | 44.9 |
| 5173 | 78 | 2026-06-01 | NULL | cancelled | 153.9 |
| 5174 | 103 | 2026-06-01 | NULL | completed | 99.9 |
| 5175 | 42 | 2026-06-02 | 9 | completed | 129 |
| 5176 | 104 | 2026-06-04 | NULL | completed | 49.9 |
| 5177 | 105 | 2026-06-08 | NULL | completed | 19.9 |
| 5178 | 50 | 2026-06-09 | NULL | completed | 102.8 |
| 5179 | 106 | 2026-06-09 | NULL | completed | 119.7 |
| 5180 | 107 | 2026-06-16 | 4 | cancelled | 29.7 |
| 5181 | 108 | 2026-06-22 | 9 | completed | 12.9 |
| 5182 | 79 | 2026-06-23 | 3 | completed | 99.9 |
| 5183 | 109 | 2026-06-26 | 4 | completed | 129 |
| 5184 | 110 | 2026-06-26 | NULL | cancelled | 24.9 |
| 5185 | 81 | 2026-06-28 | NULL | completed | 99.9 |
| 5186 | 111 | 2026-07-02 | NULL | completed | 158.9 |
| 5187 | 77 | 2026-07-04 | NULL | completed | 114.7 |
| 5188 | 112 | 2026-07-04 | NULL | completed | 39.9 |
| 5189 | 113 | 2026-07-09 | 4 | cancelled | 19.9 |
| 5190 | 114 | 2026-07-14 | NULL | completed | 49.9 |
| 5191 | 83 | 2026-07-15 | NULL | completed | 148.7 |
| 5192 | 76 | 2026-07-17 | NULL | completed | 34.9 |
| 5193 | 84 | 2026-07-17 | NULL | completed | 34.9 |
| 5194 | 115 | 2026-07-19 | NULL | completed | 79.9 |
| 5195 | 74 | 2026-07-23 | 3 | completed | 33.8 |
| 5196 | 92 | 2026-07-27 | 12 | completed | 19.9 |
| 5197 | 116 | 2026-07-27 | 12 | completed | 27.9 |
| 5198 | 117 | 2026-07-28 | NULL | completed | 99.9 |
| 5199 | 67 | 2026-07-30 | 3 | completed | 29.9 |
| 5200 | 118 | 2026-08-03 | NULL | completed | 119 |
| 5201 | 119 | 2026-08-07 | 3 | completed | 102.8 |
| 5202 | 120 | 2026-08-09 | NULL | completed | 89.9 |
| 5203 | 93 | 2026-08-15 | 3 | completed | 47.8 |
| 5204 | 121 | 2026-08-15 | NULL | completed | 27.9 |
| 5205 | 122 | 2026-08-18 | NULL | completed | 44.9 |
| 5206 | 102 | 2026-08-24 | 3 | completed | 89.8 |
| 5207 | 123 | 2026-08-25 | 12 | completed | 142.7 |
| 5208 | 124 | 2026-08-27 | 12 | completed | 113.7 |
| 5209 | 95 | 2026-08-28 | 12 | completed | 99.9 |
| 5210 | 92 | 2026-08-31 | 3 | completed | 29.8 |
| 5211 | 125 | 2026-08-31 | 3 | completed | 19.9 |
| 5212 | 110 | 2026-09-01 | NULL | completed | 42.7 |
| 5213 | 126 | 2026-09-03 | 3 | completed | 29.9 |
| 5214 | 127 | 2026-09-07 | NULL | completed | 29.8 |
| 5215 | 128 | 2026-09-13 | NULL | completed | 24.9 |
| 5216 | 129 | 2026-09-19 | 13 | completed | 89.9 |
| 5217 | 130 | 2026-09-20 | NULL | completed | 19.9 |
| 5218 | 117 | 2026-09-21 | 3 | completed | 96.8 |
| 5219 | 131 | 2026-09-22 | 3 | completed | 89.9 |
| 5220 | 50 | 2026-09-23 | NULL | completed | 44.9 |
| 5221 | 91 | 2026-09-23 | NULL | completed | 89.9 |
| 5222 | 92 | 2026-09-23 | 3 | completed | 89.9 |
| 5223 | 132 | 2026-09-26 | 12 | completed | 89.9 |
| 5224 | 115 | 2026-10-03 | NULL | completed | 25.8 |
| 5225 | 133 | 2026-10-04 | 13 | cancelled | 49.9 |
| 5226 | 63 | 2026-10-05 | NULL | completed | 24.9 |
| 5227 | 134 | 2026-10-05 | 13 | completed | 27.9 |
| 5228 | 106 | 2026-10-08 | NULL | completed | 29.9 |
| 5229 | 119 | 2026-10-08 | NULL | completed | 24.9 |
| 5230 | 135 | 2026-10-10 | 12 | completed | 24.9 |
| 5231 | 95 | 2026-10-13 | NULL | completed | 24.9 |
| 5232 | 102 | 2026-10-13 | NULL | completed | 49.9 |
| 5233 | 98 | 2026-10-14 | NULL | completed | 14.9 |
| 5234 | 136 | 2026-10-16 | 4 | completed | 24.9 |
| 5235 | 137 | 2026-10-20 | 3 | completed | 34.9 |
| 5236 | 138 | 2026-10-22 | 13 | completed | 34.9 |
| 5237 | 139 | 2026-10-27 | NULL | completed | 89.8 |
| 5238 | 140 | 2026-10-29 | 3 | completed | 19.9 |
| 5239 | 112 | 2026-10-31 | NULL | completed | 104.8 |
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.
40. Monthly streaks of regular customers
Task The CRM team is looking for customers who buy several months in a row. Show every streak of at least two consecutive calendar months in which a customer had at least one completed order each month: customer_id, start_month and end_month (first and last month of the streak as YYYY-MM) and months (the length of the streak). Sorted by months descending, then customer_id, then start_month.
orders 240 rows, 6 columns
| order_id | customer_id | order_date | campaign_id | status | amount |
|---|---|---|---|---|---|
| 5001 | 1 | 2025-01-16 | 1 | completed | 29.8 |
| 5002 | 2 | 2025-01-24 | NULL | completed | 139.7 |
| 5003 | 3 | 2025-01-28 | NULL | completed | 49.9 |
| 5004 | 4 | 2025-02-01 | 4 | completed | 69.8 |
| 5005 | 5 | 2025-02-07 | 3 | completed | 89.9 |
| 5006 | 6 | 2025-02-14 | NULL | completed | 24.9 |
| 5007 | 7 | 2025-02-25 | NULL | cancelled | 24.9 |
| 5008 | 8 | 2025-03-03 | 2 | completed | 139.7 |
| 5009 | 9 | 2025-03-06 | 2 | completed | 34.9 |
| 5010 | 6 | 2025-03-13 | NULL | completed | 24.9 |
| 5011 | 10 | 2025-03-15 | 2 | completed | 19.9 |
| 5012 | 11 | 2025-03-17 | NULL | completed | 49.9 |
| 5013 | 12 | 2025-03-29 | 3 | cancelled | 89.9 |
| 5014 | 13 | 2025-03-30 | 4 | completed | 24.9 |
| 5015 | 2 | 2025-04-03 | 3 | completed | 24.9 |
| 5016 | 14 | 2025-04-05 | 4 | completed | 79.9 |
| 5017 | 5 | 2025-04-06 | 3 | completed | 34.9 |
| 5018 | 10 | 2025-04-10 | NULL | completed | 89.9 |
| 5019 | 15 | 2025-04-12 | 3 | completed | 114.8 |
| 5020 | 16 | 2025-04-19 | 3 | completed | 99.9 |
| 5021 | 17 | 2025-04-26 | NULL | cancelled | 79.9 |
| 5022 | 7 | 2025-04-30 | NULL | completed | 29.9 |
| 5023 | 18 | 2025-05-03 | NULL | completed | 34.9 |
| 5024 | 19 | 2025-05-08 | NULL | completed | 89.9 |
| 5025 | 20 | 2025-05-12 | 3 | completed | 19.9 |
| 5026 | 21 | 2025-05-17 | 2 | cancelled | 39.9 |
| 5027 | 22 | 2025-05-18 | NULL | completed | 79.9 |
| 5028 | 14 | 2025-05-24 | 1 | completed | 89.9 |
| 5029 | 23 | 2025-05-25 | 1 | completed | 29.8 |
| 5030 | 16 | 2025-06-01 | 3 | cancelled | 27.9 |
| 5031 | 24 | 2025-06-01 | NULL | completed | 19.9 |
| 5032 | 25 | 2025-06-09 | 3 | completed | 79.9 |
| 5033 | 26 | 2025-06-15 | 6 | cancelled | 34.9 |
| 5034 | 27 | 2025-06-16 | 3 | completed | 24.9 |
| 5035 | 28 | 2025-06-18 | 6 | completed | 29.8 |
| 5036 | 29 | 2025-06-25 | 6 | completed | 19.9 |
| 5037 | 30 | 2025-07-06 | NULL | completed | 19.8 |
| 5038 | 31 | 2025-07-08 | 5 | completed | 24.9 |
| 5039 | 32 | 2025-07-10 | 5 | completed | 119.7 |
| 5040 | 33 | 2025-07-14 | 6 | completed | 49.9 |
| 5041 | 34 | 2025-07-24 | 6 | completed | 34.9 |
| 5042 | 35 | 2025-07-28 | 6 | cancelled | 89.9 |
| 5043 | 24 | 2025-07-29 | 3 | completed | 34.9 |
| 5044 | 36 | 2025-08-01 | 6 | completed | 104.8 |
| 5045 | 5 | 2025-08-05 | 3 | completed | 29.9 |
| 5046 | 37 | 2025-08-06 | NULL | cancelled | 119 |
| 5047 | 2 | 2025-08-07 | 3 | completed | 89.9 |
| 5048 | 38 | 2025-08-09 | NULL | completed | 9.9 |
| 5049 | 39 | 2025-08-14 | 6 | completed | 19.9 |
| 5050 | 40 | 2025-08-19 | 4 | completed | 89.9 |
| 5051 | 41 | 2025-08-29 | NULL | completed | 89.9 |
| 5052 | 42 | 2025-08-29 | 3 | completed | 12.9 |
| 5053 | 43 | 2025-09-03 | NULL | completed | 24.9 |
| 5054 | 44 | 2025-09-06 | 5 | completed | 34.9 |
| 5055 | 23 | 2025-09-07 | 5 | completed | 99.9 |
| 5056 | 38 | 2025-09-12 | 3 | completed | 25.8 |
| 5057 | 45 | 2025-09-15 | NULL | completed | 19.9 |
| 5058 | 46 | 2025-09-18 | 5 | completed | 99.9 |
| 5059 | 41 | 2025-09-19 | NULL | completed | 34.9 |
| 5060 | 47 | 2025-09-19 | NULL | completed | 9.9 |
| 5061 | 5 | 2025-09-24 | NULL | completed | 24.9 |
| 5062 | 48 | 2025-09-29 | NULL | completed | 79.9 |
| 5063 | 49 | 2025-09-29 | 5 | completed | 29.9 |
| 5064 | 50 | 2025-10-08 | NULL | completed | 129 |
| 5065 | 14 | 2025-10-10 | NULL | completed | 86.7 |
| 5066 | 51 | 2025-10-11 | 5 | completed | 119.7 |
| 5067 | 16 | 2025-10-12 | 5 | completed | 99.9 |
| 5068 | 52 | 2025-10-14 | 5 | completed | 119.7 |
| 5069 | 34 | 2025-10-19 | NULL | completed | 54.8 |
| 5070 | 21 | 2025-10-20 | NULL | completed | 49.9 |
| 5071 | 42 | 2025-10-20 | 5 | completed | 16.9 |
| 5072 | 53 | 2025-10-21 | 3 | completed | 89.9 |
| 5073 | 54 | 2025-10-24 | NULL | completed | 54.8 |
| 5074 | 55 | 2025-10-29 | 5 | completed | 99.9 |
| 5075 | 56 | 2025-11-04 | NULL | completed | 34.9 |
| 5076 | 57 | 2025-11-05 | 5 | completed | 114.8 |
| 5077 | 27 | 2025-11-07 | 3 | completed | 12.9 |
| 5078 | 31 | 2025-11-07 | NULL | completed | 59.9 |
| 5079 | 32 | 2025-11-07 | NULL | completed | 27.9 |
| 5080 | 58 | 2025-11-18 | NULL | completed | 19.9 |
| 5081 | 59 | 2025-11-23 | 5 | completed | 89.9 |
| 5082 | 60 | 2025-11-23 | 8 | completed | 25.8 |
| 5083 | 12 | 2025-11-24 | 7 | completed | 47.92 |
| 5084 | 15 | 2025-11-24 | 8 | completed | 91.84 |
| 5085 | 48 | 2025-11-24 | 7 | completed | 55.76 |
| 5086 | 51 | 2025-11-24 | 7 | completed | 23.92 |
| 5087 | 1 | 2025-11-25 | 7 | completed | 31.92 |
| 5088 | 7 | 2025-11-25 | NULL | completed | 47.92 |
| 5089 | 61 | 2025-11-25 | 3 | completed | 23.92 |
| 5090 | 6 | 2025-11-26 | 7 | completed | 39.92 |
| 5091 | 31 | 2025-11-26 | 8 | completed | 23.92 |
| 5092 | 56 | 2025-11-26 | 8 | completed | 10.32 |
| 5093 | 13 | 2025-11-27 | 7 | cancelled | 91.84 |
| 5094 | 30 | 2025-11-27 | 7 | completed | 31.92 |
| 5095 | 38 | 2025-11-28 | 7 | completed | 103.2 |
| 5096 | 55 | 2025-11-28 | 8 | completed | 63.92 |
| 5097 | 9 | 2025-11-29 | 8 | completed | 27.92 |
| 5098 | 5 | 2025-11-30 | 8 | completed | 15.84 |
| 5099 | 42 | 2025-11-30 | 3 | completed | 7.92 |
| 5100 | 44 | 2025-11-30 | 7 | completed | 48.56 |
| 5101 | 46 | 2025-11-30 | 7 | completed | 38.24 |
| 5102 | 47 | 2025-11-30 | 7 | completed | 31.92 |
| 5103 | 24 | 2025-12-01 | 7 | completed | 90.24 |
| 5104 | 62 | 2025-12-01 | 8 | completed | 15.92 |
| 5105 | 63 | 2025-12-08 | NULL | completed | 19.8 |
| 5106 | 64 | 2025-12-11 | NULL | completed | 114.8 |
| 5107 | 14 | 2025-12-12 | NULL | completed | 29.9 |
| 5108 | 65 | 2025-12-15 | 5 | completed | 89.7 |
| 5109 | 66 | 2025-12-19 | 5 | completed | 104.8 |
| 5110 | 67 | 2025-12-25 | NULL | completed | 34.9 |
| 5111 | 68 | 2025-12-26 | NULL | completed | 59.9 |
| 5112 | 42 | 2026-01-04 | NULL | completed | 79.9 |
| 5113 | 69 | 2026-01-06 | 10 | completed | 16.9 |
| 5114 | 70 | 2026-01-06 | 3 | completed | 19.9 |
| 5115 | 2 | 2026-01-09 | 9 | completed | 89.9 |
| 5116 | 71 | 2026-01-16 | 9 | completed | 25.8 |
| 5117 | 72 | 2026-01-17 | 9 | completed | 89.9 |
| 5118 | 50 | 2026-01-18 | NULL | completed | 19.9 |
| 5119 | 73 | 2026-01-23 | 10 | completed | 59.9 |
| 5120 | 74 | 2026-01-26 | NULL | completed | 19.8 |
| 5121 | 75 | 2026-02-02 | 9 | completed | 119 |
| 5122 | 76 | 2026-02-06 | 4 | completed | 24.9 |
| 5123 | 77 | 2026-02-07 | NULL | completed | 79.9 |
| 5124 | 78 | 2026-02-13 | NULL | completed | 9.9 |
| 5125 | 79 | 2026-02-15 | NULL | completed | 104.8 |
| 5126 | 74 | 2026-02-18 | NULL | completed | 49.9 |
| 5127 | 80 | 2026-02-20 | 4 | completed | 19.9 |
| 5128 | 68 | 2026-02-24 | NULL | completed | 12.9 |
| 5129 | 81 | 2026-02-25 | 9 | completed | 29.9 |
| 5130 | 52 | 2026-02-28 | NULL | completed | 59.9 |
| 5131 | 38 | 2026-03-01 | 3 | completed | 89.9 |
| 5132 | 82 | 2026-03-01 | NULL | completed | 19.9 |
| 5133 | 4 | 2026-03-02 | NULL | completed | 29.8 |
| 5134 | 67 | 2026-03-03 | 11 | completed | 39.9 |
| 5135 | 2 | 2026-03-05 | 9 | completed | 44.9 |
| 5136 | 17 | 2026-03-05 | NULL | completed | 79.9 |
| 5137 | 31 | 2026-03-06 | NULL | completed | 136.7 |
| 5138 | 83 | 2026-03-07 | NULL | completed | 49.9 |
| 5139 | 70 | 2026-03-08 | 11 | completed | 47.8 |
| 5140 | 84 | 2026-03-11 | 3 | completed | 49.8 |
| 5141 | 7 | 2026-03-12 | NULL | completed | 19.9 |
| 5142 | 53 | 2026-03-12 | 11 | completed | 19.9 |
| 5143 | 85 | 2026-03-12 | 4 | completed | 22.8 |
| 5144 | 5 | 2026-03-13 | NULL | cancelled | 104.8 |
| 5145 | 16 | 2026-03-14 | 9 | completed | 34.9 |
| 5146 | 57 | 2026-03-15 | NULL | completed | 107.8 |
| 5147 | 14 | 2026-03-16 | 11 | completed | 24.9 |
| 5148 | 32 | 2026-03-16 | 11 | completed | 34.9 |
| 5149 | 54 | 2026-03-17 | NULL | completed | 34.9 |
| 5150 | 86 | 2026-03-17 | NULL | completed | 25.8 |
| 5151 | 27 | 2026-03-18 | NULL | completed | 9.9 |
| 5152 | 87 | 2026-03-19 | 9 | completed | 119 |
| 5153 | 72 | 2026-03-22 | 11 | completed | 24.9 |
| 5154 | 88 | 2026-04-01 | 4 | completed | 29.9 |
| 5155 | 89 | 2026-04-05 | 9 | completed | 49.9 |
| 5156 | 90 | 2026-04-05 | 9 | completed | 102.8 |
| 5157 | 74 | 2026-04-06 | 3 | completed | 24.9 |
| 5158 | 91 | 2026-04-11 | 9 | completed | 29.9 |
| 5159 | 61 | 2026-04-12 | NULL | completed | 79.9 |
| 5160 | 92 | 2026-04-14 | NULL | completed | 29.9 |
| 5161 | 93 | 2026-04-19 | NULL | completed | 29.9 |
| 5162 | 94 | 2026-04-24 | 9 | completed | 29.9 |
| 5163 | 95 | 2026-04-28 | 4 | completed | 44.9 |
| 5164 | 96 | 2026-04-30 | 9 | completed | 129 |
| 5165 | 92 | 2026-05-07 | NULL | completed | 55.7 |
| 5166 | 97 | 2026-05-10 | 4 | completed | 54.8 |
| 5167 | 98 | 2026-05-11 | 9 | completed | 14.9 |
| 5168 | 99 | 2026-05-13 | 4 | completed | 34.9 |
| 5169 | 100 | 2026-05-18 | 9 | completed | 129 |
| 5170 | 101 | 2026-05-19 | 4 | completed | 148.7 |
| 5171 | 63 | 2026-05-23 | 3 | cancelled | 24.9 |
| 5172 | 102 | 2026-05-25 | NULL | completed | 44.9 |
| 5173 | 78 | 2026-06-01 | NULL | cancelled | 153.9 |
| 5174 | 103 | 2026-06-01 | NULL | completed | 99.9 |
| 5175 | 42 | 2026-06-02 | 9 | completed | 129 |
| 5176 | 104 | 2026-06-04 | NULL | completed | 49.9 |
| 5177 | 105 | 2026-06-08 | NULL | completed | 19.9 |
| 5178 | 50 | 2026-06-09 | NULL | completed | 102.8 |
| 5179 | 106 | 2026-06-09 | NULL | completed | 119.7 |
| 5180 | 107 | 2026-06-16 | 4 | cancelled | 29.7 |
| 5181 | 108 | 2026-06-22 | 9 | completed | 12.9 |
| 5182 | 79 | 2026-06-23 | 3 | completed | 99.9 |
| 5183 | 109 | 2026-06-26 | 4 | completed | 129 |
| 5184 | 110 | 2026-06-26 | NULL | cancelled | 24.9 |
| 5185 | 81 | 2026-06-28 | NULL | completed | 99.9 |
| 5186 | 111 | 2026-07-02 | NULL | completed | 158.9 |
| 5187 | 77 | 2026-07-04 | NULL | completed | 114.7 |
| 5188 | 112 | 2026-07-04 | NULL | completed | 39.9 |
| 5189 | 113 | 2026-07-09 | 4 | cancelled | 19.9 |
| 5190 | 114 | 2026-07-14 | NULL | completed | 49.9 |
| 5191 | 83 | 2026-07-15 | NULL | completed | 148.7 |
| 5192 | 76 | 2026-07-17 | NULL | completed | 34.9 |
| 5193 | 84 | 2026-07-17 | NULL | completed | 34.9 |
| 5194 | 115 | 2026-07-19 | NULL | completed | 79.9 |
| 5195 | 74 | 2026-07-23 | 3 | completed | 33.8 |
| 5196 | 92 | 2026-07-27 | 12 | completed | 19.9 |
| 5197 | 116 | 2026-07-27 | 12 | completed | 27.9 |
| 5198 | 117 | 2026-07-28 | NULL | completed | 99.9 |
| 5199 | 67 | 2026-07-30 | 3 | completed | 29.9 |
| 5200 | 118 | 2026-08-03 | NULL | completed | 119 |
| 5201 | 119 | 2026-08-07 | 3 | completed | 102.8 |
| 5202 | 120 | 2026-08-09 | NULL | completed | 89.9 |
| 5203 | 93 | 2026-08-15 | 3 | completed | 47.8 |
| 5204 | 121 | 2026-08-15 | NULL | completed | 27.9 |
| 5205 | 122 | 2026-08-18 | NULL | completed | 44.9 |
| 5206 | 102 | 2026-08-24 | 3 | completed | 89.8 |
| 5207 | 123 | 2026-08-25 | 12 | completed | 142.7 |
| 5208 | 124 | 2026-08-27 | 12 | completed | 113.7 |
| 5209 | 95 | 2026-08-28 | 12 | completed | 99.9 |
| 5210 | 92 | 2026-08-31 | 3 | completed | 29.8 |
| 5211 | 125 | 2026-08-31 | 3 | completed | 19.9 |
| 5212 | 110 | 2026-09-01 | NULL | completed | 42.7 |
| 5213 | 126 | 2026-09-03 | 3 | completed | 29.9 |
| 5214 | 127 | 2026-09-07 | NULL | completed | 29.8 |
| 5215 | 128 | 2026-09-13 | NULL | completed | 24.9 |
| 5216 | 129 | 2026-09-19 | 13 | completed | 89.9 |
| 5217 | 130 | 2026-09-20 | NULL | completed | 19.9 |
| 5218 | 117 | 2026-09-21 | 3 | completed | 96.8 |
| 5219 | 131 | 2026-09-22 | 3 | completed | 89.9 |
| 5220 | 50 | 2026-09-23 | NULL | completed | 44.9 |
| 5221 | 91 | 2026-09-23 | NULL | completed | 89.9 |
| 5222 | 92 | 2026-09-23 | 3 | completed | 89.9 |
| 5223 | 132 | 2026-09-26 | 12 | completed | 89.9 |
| 5224 | 115 | 2026-10-03 | NULL | completed | 25.8 |
| 5225 | 133 | 2026-10-04 | 13 | cancelled | 49.9 |
| 5226 | 63 | 2026-10-05 | NULL | completed | 24.9 |
| 5227 | 134 | 2026-10-05 | 13 | completed | 27.9 |
| 5228 | 106 | 2026-10-08 | NULL | completed | 29.9 |
| 5229 | 119 | 2026-10-08 | NULL | completed | 24.9 |
| 5230 | 135 | 2026-10-10 | 12 | completed | 24.9 |
| 5231 | 95 | 2026-10-13 | NULL | completed | 24.9 |
| 5232 | 102 | 2026-10-13 | NULL | completed | 49.9 |
| 5233 | 98 | 2026-10-14 | NULL | completed | 14.9 |
| 5234 | 136 | 2026-10-16 | 4 | completed | 24.9 |
| 5235 | 137 | 2026-10-20 | 3 | completed | 34.9 |
| 5236 | 138 | 2026-10-22 | 13 | completed | 34.9 |
| 5237 | 139 | 2026-10-27 | NULL | completed | 89.8 |
| 5238 | 140 | 2026-10-29 | 3 | completed | 19.9 |
| 5239 | 112 | 2026-10-31 | NULL | completed | 104.8 |
| 5251 | 92 | 2026-08-10 | NULL | completed | 9.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.
41. Revenue share of the top ten customers
42. Continuous sickness absence
Task The sick_days table has one row per day of sickness absence, weekends included. Company policy requires a doctor's note for any absence of more than three calendar days in a row. Show every such period: first_name, last_name, start_date, end_date (first and last day) and days, sorted by start_date.
sick_days 21 rows, 2 columns
| employee_id | sick_date |
|---|---|
| 3 | 2026-02-02 |
| 3 | 2026-02-03 |
| 3 | 2026-02-04 |
| 3 | 2026-02-05 |
| 3 | 2026-03-10 |
| 5 | 2026-03-02 |
| 5 | 2026-03-03 |
| 5 | 2026-03-04 |
| 6 | 2026-01-19 |
| 6 | 2026-01-20 |
| 6 | 2026-01-22 |
| 6 | 2026-01-23 |
| 8 | 2026-04-27 |
| 8 | 2026-04-28 |
| 8 | 2026-04-29 |
| 8 | 2026-04-30 |
| 8 | 2026-05-01 |
| 10 | 2026-05-29 |
| 10 | 2026-05-30 |
| 10 | 2026-05-31 |
| 10 | 2026-06-01 |
employees 10 rows, 7 columns
| employee_id | first_name | last_name | department | salary | hire_date | manager_id |
|---|---|---|---|---|---|---|
| 1 | Karen | Mitchell | Management | 93600 | 2018-01-02 | NULL |
| 2 | Tom | Bradley | Sales | 62400 | 2019-04-01 | 1 |
| 3 | Julia | Reyes | Sales | 46800 | 2021-06-15 | 2 |
| 4 | Marcus | Allen | Sales | 49200 | 2020-09-01 | 2 |
| 5 | Sarah | Long | Warehouse | 39600 | 2022-02-01 | 1 |
| 6 | Felix | Turner | Warehouse | 35400 | 2024-03-18 | 5 |
| 7 | Nina | Cooper | Accounting | 52800 | 2019-10-01 | 1 |
| 8 | David | Ross | Customer service | 38400 | 2023-05-02 | 2 |
| 9 | Laura | Hughes | Customer service | NULL | 2025-09-01 | 2 |
| 10 | Paul | Ward | Accounting | 43200 | 2022-11-14 | 7 |
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.
43. Salary as of a reference date
Task The salary_history table records every pay change: from valid_from the new salary applies until the next row for the same person starts. Some changes have already been agreed for later dates. For the annual report, HR needs everyone's salary on 1 January 2026: employee_id, last_name, salary and valid_from of the row in force, sorted by employee_id.
salary_history 17 rows, 3 columns
| employee_id | valid_from | salary |
|---|---|---|
| 2 | 2019-04-01 | 51600 |
| 2 | 2022-01-01 | 57600 |
| 2 | 2025-01-01 | 62400 |
| 3 | 2021-06-15 | 42000 |
| 3 | 2024-01-01 | 46800 |
| 3 | 2026-04-01 | 50400 |
| 4 | 2020-09-01 | 43200 |
| 4 | 2023-07-01 | 49200 |
| 5 | 2022-02-01 | 37200 |
| 5 | 2025-10-01 | 39600 |
| 6 | 2024-03-18 | 35400 |
| 7 | 2019-10-01 | 46800 |
| 7 | 2023-01-01 | 55200 |
| 7 | 2025-07-01 | 52800 |
| 10 | 2022-11-14 | 39600 |
| 10 | 2025-04-01 | 43200 |
| 10 | 2026-07-01 | 45600 |
employees 10 rows, 7 columns
| employee_id | first_name | last_name | department | salary | hire_date | manager_id |
|---|---|---|---|---|---|---|
| 1 | Karen | Mitchell | Management | 93600 | 2018-01-02 | NULL |
| 2 | Tom | Bradley | Sales | 62400 | 2019-04-01 | 1 |
| 3 | Julia | Reyes | Sales | 46800 | 2021-06-15 | 2 |
| 4 | Marcus | Allen | Sales | 49200 | 2020-09-01 | 2 |
| 5 | Sarah | Long | Warehouse | 39600 | 2022-02-01 | 1 |
| 6 | Felix | Turner | Warehouse | 35400 | 2024-03-18 | 5 |
| 7 | Nina | Cooper | Accounting | 52800 | 2019-10-01 | 1 |
| 8 | David | Ross | Customer service | 38400 | 2023-05-02 | 2 |
| 9 | Laura | Hughes | Customer service | NULL | 2025-09-01 | 2 |
| 10 | Paul | Ward | Accounting | 43200 | 2022-11-14 | 7 |
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.
44. Latest pay change as a percentage
Task For the pay review, HR wants to see each person's most recent pay change, even if it only takes effect in the future. For everyone with at least two rows in salary_history, show employee_id, last_name, valid_from (of the latest row), before (the salary in the row before it), after and change_pct (1 decimal place; a cut is negative). Biggest raise first.
salary_history 17 rows, 3 columns
| employee_id | valid_from | salary |
|---|---|---|
| 2 | 2019-04-01 | 51600 |
| 2 | 2022-01-01 | 57600 |
| 2 | 2025-01-01 | 62400 |
| 3 | 2021-06-15 | 42000 |
| 3 | 2024-01-01 | 46800 |
| 3 | 2026-04-01 | 50400 |
| 4 | 2020-09-01 | 43200 |
| 4 | 2023-07-01 | 49200 |
| 5 | 2022-02-01 | 37200 |
| 5 | 2025-10-01 | 39600 |
| 6 | 2024-03-18 | 35400 |
| 7 | 2019-10-01 | 46800 |
| 7 | 2023-01-01 | 55200 |
| 7 | 2025-07-01 | 52800 |
| 10 | 2022-11-14 | 39600 |
| 10 | 2025-04-01 | 43200 |
| 10 | 2026-07-01 | 45600 |
employees 10 rows, 7 columns
| employee_id | first_name | last_name | department | salary | hire_date | manager_id |
|---|---|---|---|---|---|---|
| 1 | Karen | Mitchell | Management | 93600 | 2018-01-02 | NULL |
| 2 | Tom | Bradley | Sales | 62400 | 2019-04-01 | 1 |
| 3 | Julia | Reyes | Sales | 46800 | 2021-06-15 | 2 |
| 4 | Marcus | Allen | Sales | 49200 | 2020-09-01 | 2 |
| 5 | Sarah | Long | Warehouse | 39600 | 2022-02-01 | 1 |
| 6 | Felix | Turner | Warehouse | 35400 | 2024-03-18 | 5 |
| 7 | Nina | Cooper | Accounting | 52800 | 2019-10-01 | 1 |
| 8 | David | Ross | Customer service | 38400 | 2023-05-02 | 2 |
| 9 | Laura | Hughes | Customer service | NULL | 2025-09-01 | 2 |
| 10 | Paul | Ward | Accounting | 43200 | 2022-11-14 | 7 |
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.
45. Payment delay per customer
Task Accounts receivable wants to know how punctually customers pay. Only consider invoices that are fully paid (sum of payments at least equal to the invoice amount, compared after rounding to 2 decimal places). An invoice counts as paid on the date of its last payment. For each customer, show invoices (the number of these invoices) and avg_days_late (average days from due_date to the last payment, 1 decimal place, negative when paid before the due date), biggest delay first, then by customer for ties.
invoices 60 rows, 5 columns
| invoice_id | customer | invoice_date | due_date | amount |
|---|---|---|---|---|
| 26001 | Northgate Cycles Ltd | 2026-01-03 | 2026-02-02 | 26959.83 |
| 26002 | Riverside Bike Co. | 2026-01-06 | 2026-02-05 | 14721.94 |
| 26003 | Hillcrest Cycle Shop | 2026-01-08 | 2026-02-07 | 16992.65 |
| 26004 | Pedal Point Inc. | 2026-01-12 | 2026-02-11 | 23417.22 |
| 26005 | Urban Wheels Online | 2026-01-15 | 2026-03-16 | 28124.62 |
| 26006 | Summit Outdoor Supply | 2026-01-17 | 2026-02-16 | 20273.54 |
| 26007 | Coastline Cycles | 2026-01-21 | 2026-02-20 | 12687.37 |
| 26008 | Greenway Bikes | 2026-01-23 | 2026-02-22 | 11730.56 |
| 26009 | Two Wheel Depot | 2026-01-26 | 2026-02-25 | 19622.5 |
| 26010 | Maple Street Cycles | 2026-01-29 | 2026-02-12 | 15772.49 |
| 26011 | Northgate Cycles Ltd | 2026-02-03 | 2026-03-05 | 34472.71 |
| 26012 | Riverside Bike Co. | 2026-02-05 | 2026-03-07 | 21466.08 |
| 26013 | Hillcrest Cycle Shop | 2026-02-09 | 2026-03-11 | 20975.08 |
| 26014 | Pedal Point Inc. | 2026-02-12 | 2026-03-14 | 30082.56 |
| 26015 | Urban Wheels Online | 2026-02-14 | 2026-04-15 | 40785.91 |
| 26016 | Summit Outdoor Supply | 2026-02-18 | 2026-03-20 | 24787.09 |
| 26017 | Coastline Cycles | 2026-02-21 | 2026-03-23 | 16231.53 |
| 26018 | Greenway Bikes | 2026-02-24 | 2026-03-26 | 14692.65 |
| 26019 | Two Wheel Depot | 2026-02-26 | 2026-03-28 | 26205.7 |
| 26020 | Maple Street Cycles | 2026-02-26 | 2026-03-12 | 19640.44 |
| 26021 | Northgate Cycles Ltd | 2026-03-03 | 2026-04-02 | 54429.19 |
| 26022 | Riverside Bike Co. | 2026-03-06 | 2026-04-05 | 32466.62 |
| 26023 | Hillcrest Cycle Shop | 2026-03-08 | 2026-04-07 | 34701.33 |
| 26024 | Pedal Point Inc. | 2026-03-11 | 2026-04-10 | 52082.83 |
| 26025 | Urban Wheels Online | 2026-03-14 | 2026-05-13 | 59991.26 |
| 26026 | Summit Outdoor Supply | 2026-03-17 | 2026-04-16 | 37796.33 |
| 26027 | Coastline Cycles | 2026-03-20 | 2026-04-19 | 24397.37 |
| 26028 | Greenway Bikes | 2026-03-23 | 2026-04-22 | 21785.83 |
| 26029 | Two Wheel Depot | 2026-03-27 | 2026-04-26 | 39812.27 |
| 26030 | Maple Street Cycles | 2026-03-29 | 2026-04-12 | 18452.9 |
| 26031 | Northgate Cycles Ltd | 2026-04-02 | 2026-05-02 | 59320 |
| 26032 | Riverside Bike Co. | 2026-04-06 | 2026-05-06 | 37402.19 |
| 26033 | Hillcrest Cycle Shop | 2026-04-08 | 2026-05-08 | 42329.35 |
| 26034 | Pedal Point Inc. | 2026-04-11 | 2026-05-11 | 61184.01 |
| 26035 | Urban Wheels Online | 2026-04-14 | 2026-06-13 | 75122.1 |
| 26036 | Summit Outdoor Supply | 2026-04-18 | 2026-05-18 | 42952.05 |
| 26037 | Coastline Cycles | 2026-04-20 | 2026-05-20 | 29968.46 |
| 26038 | Greenway Bikes | 2026-04-24 | 2026-05-24 | 25966.97 |
| 26039 | Two Wheel Depot | 2026-04-26 | 2026-05-26 | 50138.68 |
| 26040 | Maple Street Cycles | 2026-04-28 | 2026-05-12 | 27754.11 |
| 26041 | Northgate Cycles Ltd | 2026-05-03 | 2026-06-02 | 65530.8 |
| 26042 | Riverside Bike Co. | 2026-05-06 | 2026-06-05 | 37631.02 |
| 26043 | Hillcrest Cycle Shop | 2026-05-08 | 2026-06-07 | 41637.92 |
| 26044 | Pedal Point Inc. | 2026-05-11 | 2026-06-10 | 57840.47 |
| 26045 | Urban Wheels Online | 2026-05-14 | 2026-07-13 | 68239.27 |
| 26046 | Summit Outdoor Supply | 2026-05-17 | 2026-06-16 | 44576.3 |
| 26047 | Coastline Cycles | 2026-05-21 | 2026-06-20 | 28255.84 |
| 26048 | Greenway Bikes | 2026-05-24 | 2026-06-23 | 25800.16 |
| 26049 | Two Wheel Depot | 2026-05-26 | 2026-06-25 | 46653.8 |
| 26050 | Maple Street Cycles | 2026-05-29 | 2026-06-12 | 21711 |
| 26051 | Northgate Cycles Ltd | 2026-06-03 | 2026-07-03 | 48415.21 |
| 26052 | Riverside Bike Co. | 2026-06-06 | 2026-07-06 | 27191.07 |
| 26053 | Hillcrest Cycle Shop | 2026-06-09 | 2026-07-09 | 32156.21 |
| 26054 | Pedal Point Inc. | 2026-06-12 | 2026-07-12 | 46139.99 |
| 26055 | Urban Wheels Online | 2026-06-30 | 2026-08-29 | 55652 |
| 26056 | Summit Outdoor Supply | 2026-06-17 | 2026-07-17 | 37295.37 |
| 26057 | Coastline Cycles | 2026-06-20 | 2026-07-20 | 26031.62 |
| 26058 | Greenway Bikes | 2026-06-23 | 2026-07-23 | 21187.55 |
| 26059 | Two Wheel Depot | 2026-06-27 | 2026-07-27 | 41200.86 |
| 26060 | Maple Street Cycles | 2026-06-28 | 2026-07-12 | 14292.64 |
payments 48 rows, 4 columns
| payment_id | invoice_id | payment_date | amount |
|---|---|---|---|
| 1 | 26001 | 2026-01-31 | 26959.83 |
| 2 | 26002 | 2026-01-31 | 14721.94 |
| 3 | 26003 | 2026-02-02 | 16992.65 |
| 4 | 26004 | 2026-02-08 | 23417.22 |
| 5 | 26010 | 2026-02-09 | 15772.49 |
| 6 | 26008 | 2026-02-19 | 11730.56 |
| 7 | 26009 | 2026-02-25 | 9800 |
| 8 | 26011 | 2026-03-03 | 34472.71 |
| 9 | 26012 | 2026-03-07 | 21466.08 |
| 10 | 26013 | 2026-03-09 | 20975.08 |
| 11 | 26020 | 2026-03-09 | 19640.44 |
| 12 | 26014 | 2026-03-11 | 30082.56 |
| 13 | 26007 | 2026-03-13 | 12687.37 |
| 14 | 26005 | 2026-03-16 | 28124.62 |
| 15 | 26006 | 2026-03-16 | 20273.54 |
| 16 | 26009 | 2026-03-27 | 9822.5 |
| 17 | 26019 | 2026-03-28 | 13100 |
| 18 | 26021 | 2026-03-28 | 54429.19 |
| 19 | 26022 | 2026-03-30 | 32466.62 |
| 20 | 26023 | 2026-04-05 | 34701.33 |
| 21 | 26024 | 2026-04-05 | 52082.83 |
| 22 | 26030 | 2026-04-09 | 18452.9 |
| 23 | 26015 | 2026-04-10 | 40785.91 |
| 24 | 26017 | 2026-04-17 | 10000 |
| 25 | 26028 | 2026-04-22 | 21785.83 |
| 26 | 26016 | 2026-04-25 | 24787.09 |
| 27 | 26029 | 2026-04-26 | 19900 |
| 28 | 26019 | 2026-04-27 | 13105.7 |
| 29 | 26031 | 2026-05-01 | 59320 |
| 30 | 26032 | 2026-05-05 | 37402.19 |
| 31 | 26033 | 2026-05-05 | 42329.35 |
| 32 | 26034 | 2026-05-06 | 61184.01 |
| 33 | 26040 | 2026-05-10 | 27754.11 |
| 34 | 26025 | 2026-05-11 | 59991.26 |
| 35 | 26026 | 2026-05-11 | 37796.33 |
| 36 | 26038 | 2026-05-24 | 25966.97 |
| 37 | 26029 | 2026-05-26 | 19912.27 |
| 38 | 26039 | 2026-05-26 | 25000 |
| 39 | 26041 | 2026-06-01 | 65530.8 |
| 40 | 26043 | 2026-06-02 | 41637.92 |
| 41 | 26042 | 2026-06-05 | 37631.02 |
| 42 | 26050 | 2026-06-08 | 21711 |
| 43 | 26044 | 2026-06-09 | 57840.47 |
| 44 | 26035 | 2026-06-13 | 75122.1 |
| 45 | 26048 | 2026-06-22 | 25800.16 |
| 46 | 26036 | 2026-06-23 | 42952.05 |
| 47 | 26039 | 2026-06-25 | 25138.68 |
| 48 | 26049 | 2026-06-25 | 23300 |
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.
46. Budget peak per cost centre
Task The budget table has one column per month (jan to dec) for each cost centre. For cash planning, finance wants to know in which month each cost centre has its highest budget. Show cost_center (the name), month (as a number from 1 to 12) and budget. If several months share the top value, all of them appear. Sorted by cost_center, then month.
budget 8 rows, 13 columns
| cost_center_id | jan | feb | mar | apr | may | jun | jul | aug | sep | oct | nov | dec |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1000 | 19300 | 18800 | 19700 | 19300 | 18700 | 18800 | 19600 | 19700 | 18700 | 19000 | 19300 | 19000 |
| 1100 | 11500 | 11500 | 11500 | 11200 | 11300 | 11400 | 11500 | 11300 | 11000 | 11300 | 11000 | 11300 |
| 1200 | 12700 | 8100 | 9300 | 12700 | 8100 | 10200 | 10100 | 10100 | 10300 | 10100 | 10600 | 10100 |
| 2000 | 92900 | 107800 | 146000 | 173100 | 159400 | 140400 | 135500 | 135100 | 141600 | 141100 | 139100 | 138400 |
| 2100 | 56400 | 63800 | 91200 | 99400 | 94600 | 87200 | 83700 | 86400 | 86300 | 82200 | 84500 | 82900 |
| 2200 | 9900 | 10200 | 9900 | 10300 | 10100 | 10100 | 9600 | 10200 | 10100 | 9700 | 9900 | 9700 |
| 3000 | 13100 | 14500 | 14600 | 15800 | 13100 | 13900 | 14900 | 14800 | 15000 | 14700 | 14300 | 14300 |
| 3100 | 8900 | 10900 | 18900 | 18900 | 12900 | 12900 | 15400 | 15500 | 15600 | 15900 | 16300 | 15500 |
cost_centers 8 rows, 4 columns
| cost_center_id | name | department | manager |
|---|---|---|---|
| 1000 | Management | Administration | Laura Bennett |
| 1100 | Finance and HR | Administration | Daniel Price |
| 1200 | IT | Administration | Ryan Cooper |
| 2000 | Manufacturing | Operations | Mark Ellis |
| 2100 | Assembly | Operations | Sofia Ramirez |
| 2200 | Warehouse and shipping | Operations | Kevin Shaw |
| 3000 | Sales | Sales | James Turner |
| 3100 | Marketing | Sales | Emily Ward |
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.
47. Longest growth streak per product
Task Sales asks: for how many months in a row has each product's volume grown at most? A rise is a month in which units in sales is higher than in the previous month for the same product. For each product, show product (the name) and rises: the length of the longest run of rises directly after each other. Sorted by rises descending, then product.
sales 72 rows, 5 columns
| sale_id | product_id | month | units | revenue |
|---|---|---|---|---|
| 1 | 1 | 2026-01 | 665 | 25472.16 |
| 2 | 2 | 2026-01 | 905 | 12945.12 |
| 3 | 3 | 2026-01 | 345 | 17804.07 |
| 4 | 4 | 2026-01 | 595 | 28502.88 |
| 5 | 5 | 2026-01 | 325 | 19537.05 |
| 6 | 6 | 2026-01 | 810 | 15474.24 |
| 7 | 7 | 2026-01 | 300 | 17251.2 |
| 8 | 8 | 2026-01 | 245 | 10560.48 |
| 9 | 9 | 2026-01 | 465 | 11115.36 |
| 10 | 10 | 2026-01 | 565 | 11878.56 |
| 11 | 11 | 2026-01 | 430 | 12342.72 |
| 12 | 12 | 2026-01 | 1120 | 7418.88 |
| 13 | 1 | 2026-02 | 880 | 33707.52 |
| 14 | 2 | 2026-02 | 1210 | 17307.84 |
| 15 | 3 | 2026-02 | 505 | 26061.03 |
| 16 | 4 | 2026-02 | 695 | 33293.28 |
| 17 | 5 | 2026-02 | 400 | 24045.6 |
| 18 | 6 | 2026-02 | 905 | 17289.12 |
| 19 | 7 | 2026-02 | 460 | 26451.84 |
| 20 | 8 | 2026-02 | 330 | 14224.32 |
| 21 | 9 | 2026-02 | 600 | 14342.4 |
| 22 | 10 | 2026-02 | 855 | 17975.52 |
| 23 | 11 | 2026-02 | 510 | 14639.04 |
| 24 | 12 | 2026-02 | 1510 | 10002.24 |
| 25 | 1 | 2026-03 | 1345 | 51518.88 |
| 26 | 2 | 2026-03 | 1730 | 24745.92 |
| 27 | 3 | 2026-03 | 755 | 38962.53 |
| 28 | 4 | 2026-03 | 1170 | 56047.68 |
| 29 | 5 | 2026-03 | 380 | 32461.56 |
| 30 | 6 | 2026-03 | 1580 | 30184.32 |
| 31 | 7 | 2026-03 | 650 | 37377.6 |
| 32 | 8 | 2026-03 | 500 | 21552 |
| 33 | 9 | 2026-03 | 950 | 22708.8 |
| 34 | 10 | 2026-03 | 1170 | 24598.08 |
| 35 | 11 | 2026-03 | 760 | 21815.04 |
| 36 | 12 | 2026-03 | 2105 | 13943.52 |
| 37 | 1 | 2026-04 | 1825 | 69904.8 |
| 38 | 2 | 2026-04 | 2060 | 29466.24 |
| 39 | 3 | 2026-04 | 950 | 49025.7 |
| 40 | 4 | 2026-04 | 1250 | 59880 |
| 41 | 5 | 2026-04 | 670 | 40276.38 |
| 42 | 6 | 2026-04 | 1675 | 31999.2 |
| 43 | 7 | 2026-04 | 755 | 43415.52 |
| 44 | 8 | 2026-04 | 540 | 23276.16 |
| 45 | 9 | 2026-04 | 1105 | 26413.92 |
| 46 | 10 | 2026-04 | 1425 | 29959.2 |
| 47 | 11 | 2026-04 | 1005 | 28847.52 |
| 48 | 12 | 2026-04 | 2970 | 19673.28 |
| 49 | 1 | 2026-05 | 1550 | 59371.2 |
| 50 | 2 | 2026-05 | 2145 | 30682.08 |
| 51 | 3 | 2026-05 | 895 | 46187.37 |
| 52 | 4 | 2026-05 | 1365 | 65388.96 |
| 53 | 5 | 2026-05 | 645 | 38773.53 |
| 54 | 6 | 2026-05 | 1795 | 34291.68 |
| 55 | 7 | 2026-05 | 695 | 39965.28 |
| 56 | 8 | 2026-05 | 555 | 23922.72 |
| 57 | 9 | 2026-05 | 1085 | 25935.84 |
| 58 | 10 | 2026-05 | 1320 | 27751.68 |
| 59 | 11 | 2026-05 | 945 | 27125.28 |
| 60 | 12 | 2026-05 | 2790 | 18480.96 |
| 61 | 1 | 2026-06 | 1385 | 53051.04 |
| 62 | 2 | 2026-06 | 1625 | 23244 |
| 63 | 3 | 2026-06 | 665 | 34317.99 |
| 64 | 4 | 2026-06 | 1055 | 50538.72 |
| 65 | 5 | 2026-06 | 545 | 32762.13 |
| 66 | 6 | 2026-06 | 1360 | 25981.44 |
| 67 | 7 | 2026-06 | 595 | 34214.88 |
| 68 | 8 | 2026-06 | 390 | 16810.56 |
| 69 | 9 | 2026-06 | 815 | 19481.76 |
| 70 | 10 | 2026-06 | 1195 | 25123.68 |
| 71 | 11 | 2026-06 | 715 | 20523.36 |
| 72 | 12 | 2026-06 | 2040 | 13512.96 |
products 12 rows, 5 columns
| product_id | name | group_id | price | variable_cost |
|---|---|---|---|---|
| 1 | LED front light 70 lux | 1 | 39.9 | 17.2 |
| 2 | LED rear light | 1 | 14.9 | 6.1 |
| 3 | Rechargeable light set | 1 | 54.9 | 27.8 |
| 4 | U-lock 180 mm | 2 | 49.9 | 21.4 |
| 5 | Folding lock | 2 | 69.9 | 33.5 |
| 6 | Cable lock 120 cm | 2 | 19.9 | 14.9 |
| 7 | Pannier bag 20 l | 3 | 59.9 | 31.4 |
| 8 | Handlebar bag | 3 | 44.9 | 24.8 |
| 9 | Small saddle bag | 3 | 24.9 | 13.2 |
| 10 | Mini pump | 4 | 21.9 | 8.9 |
| 11 | Multi-tool 16 functions | 4 | 29.9 | 12.6 |
| 12 | Puncture repair kit | 4 | 6.9 | 2.1 |
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.
48. Revenue over the last 30 days
Task The dashboard shows the last 30 days of revenue for every day. For each day in October 2026 with at least one order that wasn't cancelled, show order_date, day_revenue and revenue_30d (revenue for the 30 calendar days up to and including that day, so from the date minus 29 days to the date; September orders count). Amounts to 2 decimal places, sorted by order_date.
orders 122 rows, 5 columns
| order_id | customer_id | order_date | status | amount |
|---|---|---|---|---|
| 5001 | 2 | 2025-11-01 | cancelled | 93.9 |
| 5002 | 4 | 2025-11-02 | delivered | 238.8 |
| 5003 | 6 | 2025-11-08 | delivered | 14.9 |
| 5004 | 3 | 2025-11-10 | delivered | 29.9 |
| 5005 | 7 | 2025-11-11 | delivered | 44.9 |
| 5006 | 5 | 2025-11-13 | delivered | 104.7 |
| 5007 | 11 | 2025-11-16 | delivered | 17.9 |
| 5008 | 13 | 2025-11-17 | delivered | 119 |
| 5009 | 9 | 2025-11-18 | delivered | 206.8 |
| 5010 | 10 | 2025-11-20 | delivered | 758 |
| 5011 | 12 | 2025-11-23 | delivered | 44.9 |
| 5012 | 1 | 2025-11-25 | delivered | 77.8 |
| 5013 | 4 | 2025-11-27 | delivered | 149 |
| 5014 | 8 | 2025-11-28 | delivered | 39.9 |
| 5015 | 10 | 2025-12-15 | delivered | 777.9 |
| 5016 | 14 | 2025-12-16 | delivered | 55.8 |
| 5017 | 2 | 2025-12-22 | delivered | 34.9 |
| 5018 | 16 | 2025-12-22 | delivered | 79 |
| 5019 | 15 | 2025-12-29 | delivered | 22.9 |
| 5020 | 20 | 2025-12-29 | delivered | 59.8 |
| 5021 | 21 | 2025-12-30 | delivered | 379 |
| 5022 | 19 | 2025-12-31 | delivered | 114.7 |
| 5023 | 17 | 2026-01-03 | delivered | 49.8 |
| 5024 | 18 | 2026-01-08 | delivered | 79 |
| 5025 | 6 | 2026-01-14 | delivered | 44.9 |
| 5026 | 11 | 2026-01-16 | delivered | 12.9 |
| 5027 | 9 | 2026-01-17 | delivered | 49.9 |
| 5028 | 2 | 2026-01-21 | delivered | 59.9 |
| 5029 | 22 | 2026-01-24 | delivered | 49.9 |
| 5030 | 24 | 2026-01-25 | delivered | 498 |
| 5031 | 25 | 2026-02-04 | delivered | 413.9 |
| 5032 | 5 | 2026-02-05 | delivered | 34.9 |
| 5033 | 28 | 2026-02-06 | cancelled | 34.9 |
| 5034 | 26 | 2026-02-11 | delivered | 17.9 |
| 5035 | 11 | 2026-02-20 | delivered | 39.9 |
| 5036 | 21 | 2026-02-23 | delivered | 170.9 |
| 5037 | 29 | 2026-02-25 | delivered | 49.9 |
| 5038 | 27 | 2026-02-26 | delivered | 24.9 |
| 5039 | 12 | 2026-03-03 | delivered | 308 |
| 5040 | 18 | 2026-03-03 | delivered | 26.9 |
| 5041 | 15 | 2026-03-06 | delivered | 99.6 |
| 5042 | 1 | 2026-03-07 | delivered | 403.8 |
| 5043 | 31 | 2026-03-11 | delivered | 417.7 |
| 5044 | 30 | 2026-03-12 | delivered | 149 |
| 5045 | 33 | 2026-03-13 | delivered | 158 |
| 5046 | 34 | 2026-03-19 | delivered | 189 |
| 5047 | 32 | 2026-03-27 | delivered | 123.8 |
| 5048 | 35 | 2026-03-30 | delivered | 93.9 |
| 5049 | 19 | 2026-04-01 | delivered | 69.8 |
| 5050 | 2 | 2026-04-04 | cancelled | 368.9 |
| 5051 | 34 | 2026-04-06 | delivered | 47.8 |
| 5052 | 20 | 2026-04-16 | delivered | 119 |
| 5053 | 6 | 2026-04-22 | delivered | 258.7 |
| 5054 | 2 | 2026-04-23 | cancelled | 126.7 |
| 5055 | 11 | 2026-04-24 | delivered | 29.9 |
| 5056 | 36 | 2026-04-26 | delivered | 79 |
| 5057 | 37 | 2026-04-26 | cancelled | 12.9 |
| 5058 | 39 | 2026-04-27 | delivered | 117.7 |
| 5059 | 38 | 2026-04-29 | delivered | 19.9 |
| 5060 | 22 | 2026-04-30 | delivered | 59.9 |
| 5061 | 99 | 2026-05-01 | delivered | 63.7 |
| 5062 | 40 | 2026-05-04 | delivered | 158 |
| 5063 | 41 | 2026-05-05 | delivered | 378 |
| 5064 | 29 | 2026-05-14 | delivered | 228.7 |
| 5065 | 43 | 2026-05-17 | delivered | 74.7 |
| 5066 | 45 | 2026-05-25 | cancelled | 39.9 |
| 5067 | 44 | 2026-05-27 | delivered | 69.8 |
| 5068 | 46 | 2026-05-31 | delivered | 80.7 |
| 5069 | 27 | 2026-06-04 | delivered | 97.7 |
| 5070 | 31 | 2026-06-09 | delivered | 68.7 |
| 5071 | 18 | 2026-06-10 | delivered | 189 |
| 5072 | 19 | 2026-06-11 | delivered | 57.7 |
| 5073 | 35 | 2026-06-13 | delivered | 149 |
| 5074 | 47 | 2026-06-19 | delivered | 119 |
| 5075 | 49 | 2026-06-20 | delivered | 39.9 |
| 5076 | 48 | 2026-06-23 | delivered | 49.9 |
| 5077 | 42 | 2026-06-25 | delivered | 19.9 |
| 5078 | 51 | 2026-06-27 | delivered | 34.9 |
| 5079 | 39 | 2026-07-01 | delivered | 59.7 |
| 5080 | 50 | 2026-07-01 | delivered | 25.8 |
| 5081 | 45 | 2026-07-02 | delivered | 188.8 |
| 5082 | 19 | 2026-07-04 | delivered | 134.4 |
| 5083 | 53 | 2026-07-12 | delivered | 83.7 |
| 5084 | 52 | 2026-07-14 | delivered | 77.8 |
| 5085 | 38 | 2026-07-15 | delivered | 129.7 |
| 5086 | 54 | 2026-07-15 | delivered | 418.8 |
| 5087 | 46 | 2026-07-17 | delivered | 59.8 |
| 5088 | 29 | 2026-07-19 | delivered | 188.9 |
| 5089 | 36 | 2026-07-19 | delivered | 124.7 |
| 5090 | 45 | 2026-07-27 | delivered | 14.9 |
| 5091 | 41 | 2026-07-29 | delivered | 19.9 |
| 5092 | 58 | 2026-08-01 | delivered | 99.8 |
| 5093 | 56 | 2026-08-05 | delivered | 74.7 |
| 5094 | 53 | 2026-08-06 | delivered | 98.9 |
| 5095 | 59 | 2026-08-07 | delivered | 22.9 |
| 5096 | 18 | 2026-08-12 | delivered | 1157 |
| 5097 | 61 | 2026-08-16 | delivered | 44.7 |
| 5098 | 29 | 2026-08-20 | delivered | 105.7 |
| 5099 | 60 | 2026-08-24 | delivered | 307 |
| 5100 | 39 | 2026-08-27 | delivered | 103.9 |
| 5101 | 44 | 2026-08-28 | delivered | 243.8 |
| 5102 | 31 | 2026-08-31 | delivered | 128.9 |
| 5103 | 54 | 2026-08-31 | delivered | 298 |
| 5104 | 42 | 2026-09-01 | delivered | 388.9 |
| 5105 | 47 | 2026-09-01 | delivered | 124.7 |
| 5106 | 63 | 2026-09-06 | cancelled | 14.9 |
| 5107 | 64 | 2026-09-06 | delivered | 62.8 |
| 5108 | 65 | 2026-09-06 | cancelled | 208.6 |
| 5109 | 62 | 2026-09-11 | delivered | 34.9 |
| 5110 | 27 | 2026-09-18 | delivered | 29.9 |
| 5111 | 42 | 2026-09-20 | delivered | 104.7 |
| 5112 | 41 | 2026-09-21 | delivered | 24.9 |
| 5113 | 46 | 2026-09-27 | delivered | 94.6 |
| 5114 | 66 | 2026-09-28 | delivered | 29.9 |
| 5115 | 67 | 2026-10-01 | delivered | 34.9 |
| 5116 | 51 | 2026-10-07 | delivered | 69.8 |
| 5117 | 53 | 2026-10-07 | cancelled | 34.9 |
| 5118 | 70 | 2026-10-09 | delivered | 211.9 |
| 5119 | 64 | 2026-10-16 | delivered | 698 |
| 5120 | 68 | 2026-10-21 | delivered | 183.9 |
| 5121 | 69 | 2026-10-27 | shipped | 159.4 |
| 5122 | 27 | 2026-10-30 | shipped | 118.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.
49. Repeat purchase within 60 days
Task How many first-time buyers come back soon? Group customers by the quarter of their first completed order (cohort, format '2025-Q1'). A repeat purchase is another completed order (a different order_id) within 60 days of the day of the first one, that day included. So that every cohort gets a full 60 days, only include cohorts up to and including 2026-Q2. Show cohort, first_buyers, repeat_buyers and repeat_pct (1 decimal place), sorted by cohort.
orders 239 rows, 6 columns
| order_id | customer_id | order_date | campaign_id | status | amount |
|---|---|---|---|---|---|
| 5001 | 1 | 2025-01-16 | 1 | completed | 29.8 |
| 5002 | 2 | 2025-01-24 | NULL | completed | 139.7 |
| 5003 | 3 | 2025-01-28 | NULL | completed | 49.9 |
| 5004 | 4 | 2025-02-01 | 4 | completed | 69.8 |
| 5005 | 5 | 2025-02-07 | 3 | completed | 89.9 |
| 5006 | 6 | 2025-02-14 | NULL | completed | 24.9 |
| 5007 | 7 | 2025-02-25 | NULL | cancelled | 24.9 |
| 5008 | 8 | 2025-03-03 | 2 | completed | 139.7 |
| 5009 | 9 | 2025-03-06 | 2 | completed | 34.9 |
| 5010 | 6 | 2025-03-13 | NULL | completed | 24.9 |
| 5011 | 10 | 2025-03-15 | 2 | completed | 19.9 |
| 5012 | 11 | 2025-03-17 | NULL | completed | 49.9 |
| 5013 | 12 | 2025-03-29 | 3 | cancelled | 89.9 |
| 5014 | 13 | 2025-03-30 | 4 | completed | 24.9 |
| 5015 | 2 | 2025-04-03 | 3 | completed | 24.9 |
| 5016 | 14 | 2025-04-05 | 4 | completed | 79.9 |
| 5017 | 5 | 2025-04-06 | 3 | completed | 34.9 |
| 5018 | 10 | 2025-04-10 | NULL | completed | 89.9 |
| 5019 | 15 | 2025-04-12 | 3 | completed | 114.8 |
| 5020 | 16 | 2025-04-19 | 3 | completed | 99.9 |
| 5021 | 17 | 2025-04-26 | NULL | cancelled | 79.9 |
| 5022 | 7 | 2025-04-30 | NULL | completed | 29.9 |
| 5023 | 18 | 2025-05-03 | NULL | completed | 34.9 |
| 5024 | 19 | 2025-05-08 | NULL | completed | 89.9 |
| 5025 | 20 | 2025-05-12 | 3 | completed | 19.9 |
| 5026 | 21 | 2025-05-17 | 2 | cancelled | 39.9 |
| 5027 | 22 | 2025-05-18 | NULL | completed | 79.9 |
| 5028 | 14 | 2025-05-24 | 1 | completed | 89.9 |
| 5029 | 23 | 2025-05-25 | 1 | completed | 29.8 |
| 5030 | 16 | 2025-06-01 | 3 | cancelled | 27.9 |
| 5031 | 24 | 2025-06-01 | NULL | completed | 19.9 |
| 5032 | 25 | 2025-06-09 | 3 | completed | 79.9 |
| 5033 | 26 | 2025-06-15 | 6 | cancelled | 34.9 |
| 5034 | 27 | 2025-06-16 | 3 | completed | 24.9 |
| 5035 | 28 | 2025-06-18 | 6 | completed | 29.8 |
| 5036 | 29 | 2025-06-25 | 6 | completed | 19.9 |
| 5037 | 30 | 2025-07-06 | NULL | completed | 19.8 |
| 5038 | 31 | 2025-07-08 | 5 | completed | 24.9 |
| 5039 | 32 | 2025-07-10 | 5 | completed | 119.7 |
| 5040 | 33 | 2025-07-14 | 6 | completed | 49.9 |
| 5041 | 34 | 2025-07-24 | 6 | completed | 34.9 |
| 5042 | 35 | 2025-07-28 | 6 | cancelled | 89.9 |
| 5043 | 24 | 2025-07-29 | 3 | completed | 34.9 |
| 5044 | 36 | 2025-08-01 | 6 | completed | 104.8 |
| 5045 | 5 | 2025-08-05 | 3 | completed | 29.9 |
| 5046 | 37 | 2025-08-06 | NULL | cancelled | 119 |
| 5047 | 2 | 2025-08-07 | 3 | completed | 89.9 |
| 5048 | 38 | 2025-08-09 | NULL | completed | 9.9 |
| 5049 | 39 | 2025-08-14 | 6 | completed | 19.9 |
| 5050 | 40 | 2025-08-19 | 4 | completed | 89.9 |
| 5051 | 41 | 2025-08-29 | NULL | completed | 89.9 |
| 5052 | 42 | 2025-08-29 | 3 | completed | 12.9 |
| 5053 | 43 | 2025-09-03 | NULL | completed | 24.9 |
| 5054 | 44 | 2025-09-06 | 5 | completed | 34.9 |
| 5055 | 23 | 2025-09-07 | 5 | completed | 99.9 |
| 5056 | 38 | 2025-09-12 | 3 | completed | 25.8 |
| 5057 | 45 | 2025-09-15 | NULL | completed | 19.9 |
| 5058 | 46 | 2025-09-18 | 5 | completed | 99.9 |
| 5059 | 41 | 2025-09-19 | NULL | completed | 34.9 |
| 5060 | 47 | 2025-09-19 | NULL | completed | 9.9 |
| 5061 | 5 | 2025-09-24 | NULL | completed | 24.9 |
| 5062 | 48 | 2025-09-29 | NULL | completed | 79.9 |
| 5063 | 49 | 2025-09-29 | 5 | completed | 29.9 |
| 5064 | 50 | 2025-10-08 | NULL | completed | 129 |
| 5065 | 14 | 2025-10-10 | NULL | completed | 86.7 |
| 5066 | 51 | 2025-10-11 | 5 | completed | 119.7 |
| 5067 | 16 | 2025-10-12 | 5 | completed | 99.9 |
| 5068 | 52 | 2025-10-14 | 5 | completed | 119.7 |
| 5069 | 34 | 2025-10-19 | NULL | completed | 54.8 |
| 5070 | 21 | 2025-10-20 | NULL | completed | 49.9 |
| 5071 | 42 | 2025-10-20 | 5 | completed | 16.9 |
| 5072 | 53 | 2025-10-21 | 3 | completed | 89.9 |
| 5073 | 54 | 2025-10-24 | NULL | completed | 54.8 |
| 5074 | 55 | 2025-10-29 | 5 | completed | 99.9 |
| 5075 | 56 | 2025-11-04 | NULL | completed | 34.9 |
| 5076 | 57 | 2025-11-05 | 5 | completed | 114.8 |
| 5077 | 27 | 2025-11-07 | 3 | completed | 12.9 |
| 5078 | 31 | 2025-11-07 | NULL | completed | 59.9 |
| 5079 | 32 | 2025-11-07 | NULL | completed | 27.9 |
| 5080 | 58 | 2025-11-18 | NULL | completed | 19.9 |
| 5081 | 59 | 2025-11-23 | 5 | completed | 89.9 |
| 5082 | 60 | 2025-11-23 | 8 | completed | 25.8 |
| 5083 | 12 | 2025-11-24 | 7 | completed | 47.92 |
| 5084 | 15 | 2025-11-24 | 8 | completed | 91.84 |
| 5085 | 48 | 2025-11-24 | 7 | completed | 55.76 |
| 5086 | 51 | 2025-11-24 | 7 | completed | 23.92 |
| 5087 | 1 | 2025-11-25 | 7 | completed | 31.92 |
| 5088 | 7 | 2025-11-25 | NULL | completed | 47.92 |
| 5089 | 61 | 2025-11-25 | 3 | completed | 23.92 |
| 5090 | 6 | 2025-11-26 | 7 | completed | 39.92 |
| 5091 | 31 | 2025-11-26 | 8 | completed | 23.92 |
| 5092 | 56 | 2025-11-26 | 8 | completed | 10.32 |
| 5093 | 13 | 2025-11-27 | 7 | cancelled | 91.84 |
| 5094 | 30 | 2025-11-27 | 7 | completed | 31.92 |
| 5095 | 38 | 2025-11-28 | 7 | completed | 103.2 |
| 5096 | 55 | 2025-11-28 | 8 | completed | 63.92 |
| 5097 | 9 | 2025-11-29 | 8 | completed | 27.92 |
| 5098 | 5 | 2025-11-30 | 8 | completed | 15.84 |
| 5099 | 42 | 2025-11-30 | 3 | completed | 7.92 |
| 5100 | 44 | 2025-11-30 | 7 | completed | 48.56 |
| 5101 | 46 | 2025-11-30 | 7 | completed | 38.24 |
| 5102 | 47 | 2025-11-30 | 7 | completed | 31.92 |
| 5103 | 24 | 2025-12-01 | 7 | completed | 90.24 |
| 5104 | 62 | 2025-12-01 | 8 | completed | 15.92 |
| 5105 | 63 | 2025-12-08 | NULL | completed | 19.8 |
| 5106 | 64 | 2025-12-11 | NULL | completed | 114.8 |
| 5107 | 14 | 2025-12-12 | NULL | completed | 29.9 |
| 5108 | 65 | 2025-12-15 | 5 | completed | 89.7 |
| 5109 | 66 | 2025-12-19 | 5 | completed | 104.8 |
| 5110 | 67 | 2025-12-25 | NULL | completed | 34.9 |
| 5111 | 68 | 2025-12-26 | NULL | completed | 59.9 |
| 5112 | 42 | 2026-01-04 | NULL | completed | 79.9 |
| 5113 | 69 | 2026-01-06 | 10 | completed | 16.9 |
| 5114 | 70 | 2026-01-06 | 3 | completed | 19.9 |
| 5115 | 2 | 2026-01-09 | 9 | completed | 89.9 |
| 5116 | 71 | 2026-01-16 | 9 | completed | 25.8 |
| 5117 | 72 | 2026-01-17 | 9 | completed | 89.9 |
| 5118 | 50 | 2026-01-18 | NULL | completed | 19.9 |
| 5119 | 73 | 2026-01-23 | 10 | completed | 59.9 |
| 5120 | 74 | 2026-01-26 | NULL | completed | 19.8 |
| 5121 | 75 | 2026-02-02 | 9 | completed | 119 |
| 5122 | 76 | 2026-02-06 | 4 | completed | 24.9 |
| 5123 | 77 | 2026-02-07 | NULL | completed | 79.9 |
| 5124 | 78 | 2026-02-13 | NULL | completed | 9.9 |
| 5125 | 79 | 2026-02-15 | NULL | completed | 104.8 |
| 5126 | 74 | 2026-02-18 | NULL | completed | 49.9 |
| 5127 | 80 | 2026-02-20 | 4 | completed | 19.9 |
| 5128 | 68 | 2026-02-24 | NULL | completed | 12.9 |
| 5129 | 81 | 2026-02-25 | 9 | completed | 29.9 |
| 5130 | 52 | 2026-02-28 | NULL | completed | 59.9 |
| 5131 | 38 | 2026-03-01 | 3 | completed | 89.9 |
| 5132 | 82 | 2026-03-01 | NULL | completed | 19.9 |
| 5133 | 4 | 2026-03-02 | NULL | completed | 29.8 |
| 5134 | 67 | 2026-03-03 | 11 | completed | 39.9 |
| 5135 | 2 | 2026-03-05 | 9 | completed | 44.9 |
| 5136 | 17 | 2026-03-05 | NULL | completed | 79.9 |
| 5137 | 31 | 2026-03-06 | NULL | completed | 136.7 |
| 5138 | 83 | 2026-03-07 | NULL | completed | 49.9 |
| 5139 | 70 | 2026-03-08 | 11 | completed | 47.8 |
| 5140 | 84 | 2026-03-11 | 3 | completed | 49.8 |
| 5141 | 7 | 2026-03-12 | NULL | completed | 19.9 |
| 5142 | 53 | 2026-03-12 | 11 | completed | 19.9 |
| 5143 | 85 | 2026-03-12 | 4 | completed | 22.8 |
| 5144 | 5 | 2026-03-13 | NULL | cancelled | 104.8 |
| 5145 | 16 | 2026-03-14 | 9 | completed | 34.9 |
| 5146 | 57 | 2026-03-15 | NULL | completed | 107.8 |
| 5147 | 14 | 2026-03-16 | 11 | completed | 24.9 |
| 5148 | 32 | 2026-03-16 | 11 | completed | 34.9 |
| 5149 | 54 | 2026-03-17 | NULL | completed | 34.9 |
| 5150 | 86 | 2026-03-17 | NULL | completed | 25.8 |
| 5151 | 27 | 2026-03-18 | NULL | completed | 9.9 |
| 5152 | 87 | 2026-03-19 | 9 | completed | 119 |
| 5153 | 72 | 2026-03-22 | 11 | completed | 24.9 |
| 5154 | 88 | 2026-04-01 | 4 | completed | 29.9 |
| 5155 | 89 | 2026-04-05 | 9 | completed | 49.9 |
| 5156 | 90 | 2026-04-05 | 9 | completed | 102.8 |
| 5157 | 74 | 2026-04-06 | 3 | completed | 24.9 |
| 5158 | 91 | 2026-04-11 | 9 | completed | 29.9 |
| 5159 | 61 | 2026-04-12 | NULL | completed | 79.9 |
| 5160 | 92 | 2026-04-14 | NULL | completed | 29.9 |
| 5161 | 93 | 2026-04-19 | NULL | completed | 29.9 |
| 5162 | 94 | 2026-04-24 | 9 | completed | 29.9 |
| 5163 | 95 | 2026-04-28 | 4 | completed | 44.9 |
| 5164 | 96 | 2026-04-30 | 9 | completed | 129 |
| 5165 | 92 | 2026-05-07 | NULL | completed | 55.7 |
| 5166 | 97 | 2026-05-10 | 4 | completed | 54.8 |
| 5167 | 98 | 2026-05-11 | 9 | completed | 14.9 |
| 5168 | 99 | 2026-05-13 | 4 | completed | 34.9 |
| 5169 | 100 | 2026-05-18 | 9 | completed | 129 |
| 5170 | 101 | 2026-05-19 | 4 | completed | 148.7 |
| 5171 | 63 | 2026-05-23 | 3 | cancelled | 24.9 |
| 5172 | 102 | 2026-05-25 | NULL | completed | 44.9 |
| 5173 | 78 | 2026-06-01 | NULL | cancelled | 153.9 |
| 5174 | 103 | 2026-06-01 | NULL | completed | 99.9 |
| 5175 | 42 | 2026-06-02 | 9 | completed | 129 |
| 5176 | 104 | 2026-06-04 | NULL | completed | 49.9 |
| 5177 | 105 | 2026-06-08 | NULL | completed | 19.9 |
| 5178 | 50 | 2026-06-09 | NULL | completed | 102.8 |
| 5179 | 106 | 2026-06-09 | NULL | completed | 119.7 |
| 5180 | 107 | 2026-06-16 | 4 | cancelled | 29.7 |
| 5181 | 108 | 2026-06-22 | 9 | completed | 12.9 |
| 5182 | 79 | 2026-06-23 | 3 | completed | 99.9 |
| 5183 | 109 | 2026-06-26 | 4 | completed | 129 |
| 5184 | 110 | 2026-06-26 | NULL | cancelled | 24.9 |
| 5185 | 81 | 2026-06-28 | NULL | completed | 99.9 |
| 5186 | 111 | 2026-07-02 | NULL | completed | 158.9 |
| 5187 | 77 | 2026-07-04 | NULL | completed | 114.7 |
| 5188 | 112 | 2026-07-04 | NULL | completed | 39.9 |
| 5189 | 113 | 2026-07-09 | 4 | cancelled | 19.9 |
| 5190 | 114 | 2026-07-14 | NULL | completed | 49.9 |
| 5191 | 83 | 2026-07-15 | NULL | completed | 148.7 |
| 5192 | 76 | 2026-07-17 | NULL | completed | 34.9 |
| 5193 | 84 | 2026-07-17 | NULL | completed | 34.9 |
| 5194 | 115 | 2026-07-19 | NULL | completed | 79.9 |
| 5195 | 74 | 2026-07-23 | 3 | completed | 33.8 |
| 5196 | 92 | 2026-07-27 | 12 | completed | 19.9 |
| 5197 | 116 | 2026-07-27 | 12 | completed | 27.9 |
| 5198 | 117 | 2026-07-28 | NULL | completed | 99.9 |
| 5199 | 67 | 2026-07-30 | 3 | completed | 29.9 |
| 5200 | 118 | 2026-08-03 | NULL | completed | 119 |
| 5201 | 119 | 2026-08-07 | 3 | completed | 102.8 |
| 5202 | 120 | 2026-08-09 | NULL | completed | 89.9 |
| 5203 | 93 | 2026-08-15 | 3 | completed | 47.8 |
| 5204 | 121 | 2026-08-15 | NULL | completed | 27.9 |
| 5205 | 122 | 2026-08-18 | NULL | completed | 44.9 |
| 5206 | 102 | 2026-08-24 | 3 | completed | 89.8 |
| 5207 | 123 | 2026-08-25 | 12 | completed | 142.7 |
| 5208 | 124 | 2026-08-27 | 12 | completed | 113.7 |
| 5209 | 95 | 2026-08-28 | 12 | completed | 99.9 |
| 5210 | 92 | 2026-08-31 | 3 | completed | 29.8 |
| 5211 | 125 | 2026-08-31 | 3 | completed | 19.9 |
| 5212 | 110 | 2026-09-01 | NULL | completed | 42.7 |
| 5213 | 126 | 2026-09-03 | 3 | completed | 29.9 |
| 5214 | 127 | 2026-09-07 | NULL | completed | 29.8 |
| 5215 | 128 | 2026-09-13 | NULL | completed | 24.9 |
| 5216 | 129 | 2026-09-19 | 13 | completed | 89.9 |
| 5217 | 130 | 2026-09-20 | NULL | completed | 19.9 |
| 5218 | 117 | 2026-09-21 | 3 | completed | 96.8 |
| 5219 | 131 | 2026-09-22 | 3 | completed | 89.9 |
| 5220 | 50 | 2026-09-23 | NULL | completed | 44.9 |
| 5221 | 91 | 2026-09-23 | NULL | completed | 89.9 |
| 5222 | 92 | 2026-09-23 | 3 | completed | 89.9 |
| 5223 | 132 | 2026-09-26 | 12 | completed | 89.9 |
| 5224 | 115 | 2026-10-03 | NULL | completed | 25.8 |
| 5225 | 133 | 2026-10-04 | 13 | cancelled | 49.9 |
| 5226 | 63 | 2026-10-05 | NULL | completed | 24.9 |
| 5227 | 134 | 2026-10-05 | 13 | completed | 27.9 |
| 5228 | 106 | 2026-10-08 | NULL | completed | 29.9 |
| 5229 | 119 | 2026-10-08 | NULL | completed | 24.9 |
| 5230 | 135 | 2026-10-10 | 12 | completed | 24.9 |
| 5231 | 95 | 2026-10-13 | NULL | completed | 24.9 |
| 5232 | 102 | 2026-10-13 | NULL | completed | 49.9 |
| 5233 | 98 | 2026-10-14 | NULL | completed | 14.9 |
| 5234 | 136 | 2026-10-16 | 4 | completed | 24.9 |
| 5235 | 137 | 2026-10-20 | 3 | completed | 34.9 |
| 5236 | 138 | 2026-10-22 | 13 | completed | 34.9 |
| 5237 | 139 | 2026-10-27 | NULL | completed | 89.8 |
| 5238 | 140 | 2026-10-29 | 3 | completed | 19.9 |
| 5239 | 112 | 2026-10-31 | NULL | completed | 104.8 |
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.
50. Overlapping campaigns in the same channel
Task When two campaigns in the same channel run at the same time, revenue is hard to attribute. Show every pair of campaigns in the same channel whose run times overlap by at least one day, exactly once: campaign_1 and campaign_2 (names; the one with the smaller campaign_id first), channel and days (the number of shared days, first and last included). Longest overlap first.
campaigns 14 rows, 6 columns
| campaign_id | name | channel | start_date | end_date | cost |
|---|---|---|---|---|---|
| 1 | Paid search H1 2025 | Paid Search | 2025-01-01 | 2025-06-30 | 120 |
| 2 | Paid social spring 2025 | Paid Social | 2025-03-01 | 2025-05-31 | 160 |
| 3 | Email newsletter (ongoing) | 2025-01-01 | 2026-12-31 | 360 | |
| 4 | Affiliate program sports blogs | Affiliate | 2025-01-01 | 2026-12-31 | 240 |
| 5 | Paid search H2 2025 | Paid Search | 2025-07-01 | 2025-12-31 | 420 |
| 6 | Paid social summer 2025 | Paid Social | 2025-06-15 | 2025-08-31 | 180 |
| 7 | Email Black Friday week 2025 | 2025-11-24 | 2025-12-01 | 40 | |
| 8 | Paid social Black Friday week 2025 | Paid Social | 2025-11-20 | 2025-12-01 | 230 |
| 9 | Paid search H1 2026 | Paid Search | 2026-01-01 | 2026-06-30 | 450 |
| 10 | Paid social fitness January 2026 | Paid Social | 2026-01-02 | 2026-01-31 | 150 |
| 11 | Email spring sale 2026 | 2026-03-02 | 2026-03-31 | 40 | |
| 12 | Paid search H2 2026 | Paid Search | 2026-07-01 | 2026-12-31 | 380 |
| 13 | Paid social Sep/Oct 2026 | Paid Social | 2026-09-15 | 2026-10-31 | 220 |
| 14 | Paid social video test | Paid Social | 2026-05-04 | 2026-05-24 | 120 |
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
- Break it down instead of nesting: one CTE per idea reads like an explanation and can be checked on its own.
- Gaps and islands: value minus row number is constant within an unbroken run. This trick solves streaks of days, months or numbers.
- Measure time properly: running numbers for months and quarters, julianday for days, RANGE instead of ROWS for time windows.
- Name the edge cases: odd or even count for the median, an incomplete last quarter, future salary rows. In an interview, what counts is that you see them.
FAQ
What do I need to know for the advanced questions?
Everything from the intermediate questions, plus confident use of window functions with PARTITION BY and frames (ROWS, RANGE), several CTEs in a row and date arithmetic.
Do questions like these really come up in interviews?
The patterns do: median, streaks, repeat purchases, retention and values as of a date are well-known questions for roles with a lot of SQL. We don't know which questions a particular company uses; the questions here are written from scratch for the practice data.
How do I prepare for the rest of the interview?
The concept questions about indexes, transactions or the difference between WHERE and HAVING are on the SQL interview questions page, with short answers.