Case 6: Customer lifetime value over 12 months
Case 2 showed what a new customer costs. Now for the other side of the ledger: what do they bring in? You work out customer value over a fixed twelve-month window, first as revenue, then as gross margin.
In short: a CTE returns each customer's first completed order. The window ends at date(first_order, '+12 months'), and everything before that counts. Only customers whose window lies completely inside the data are included. For gross margin, calculate from the order lines: quantity * (unit_price - unit_cost).
The situation
CLV stands for customer lifetime value, what a customer is worth over the whole relationship. Nobody knows the whole relationship in advance, so many teams measure a historical value over a fixed window instead, such as the first twelve months. It is a measurement rather than a forecast, and it has one big advantage: customers from different months become directly comparable. Leadership wants to know which acquisition channel brings in the most valuable customers, so the figure can sit next to the cost per new customer.
The data
You need orders for date and status, order_items for quantity and unit_price, products for unit_cost and customers for the channel. The data ends on 31 October 2026, so a twelve-month window is only complete for customers whose first completed order falls between 1 January and 31 October 2025.
SQLite adds months with a modifier in date(). If the day does not exist in the target month, the date rolls over into the next month:
SELECT date('2025-01-24', '+12 months') AS window_end,
date('2025-10-31', '+1 month') AS rollover;
| window_end | rollover |
|---|---|
| 2026-01-24 | 2025-12-01 |
For twelve months from a day in 2025 this does not matter: 2026 is not a leap year, and every day exists again a year later.
Task 1: first-year revenue
Task How much revenue does a customer bring in during their first 12 months? Take every customer whose first completed order falls between 1 January and 31 October 2025; only for them is the window complete by the end of October 2026. Show customer_id, first_order (the date) and revenue_12m: the sum of amount over all completed orders from the first one up to, but not including, the same day 12 months later.
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 |
How it works
The CTE finds each customer's MIN(order_date) among completed orders. That is not always the signup_date: customer 7 signed up on 25 February 2025 with an order that was cancelled, and their first completed order came on 30 April. You then join the CTE to orders and only add up orders before the end of the window.
An example: customer 2 bought five times, most recently on 5 March 2026. Their window runs from 24 January 2025 to just before 24 January 2026. Four orders fall inside it, worth 344.4 together. The fifth no longer counts, even though it is part of their total spend of 389.3.
Task 2: customer value and gross margin by channel
Task Which acquisition channel brings in the most valuable customers? Use the same customers and the same 12-month window as in task 1, but calculate from the order items. For each channel (from customers), show the number of customers, the average revenue_12m (sum of quantity * unit_price per customer, average to 2 decimal places) and the average margin_12m, the gross margin (sum of quantity * (unit_price - unit_cost) per customer, average to 2 decimal places).
customers 140 rows, 6 columns
| customer_id | name | city | signup_date | channel | campaign_id |
|---|---|---|---|---|---|
| 1 | Sophia Campbell | Leeds | 2025-01-16 | Paid Search | 1 |
| 2 | Aiden Allen | Leeds | 2025-01-24 | Organic | NULL |
| 3 | Aiden Miller | Austin | 2025-01-28 | Organic | NULL |
| 4 | Isla Wright | Glasgow | 2025-02-01 | Affiliate | 4 |
| 5 | Henry Garcia | Glasgow | 2025-02-07 | 3 | |
| 6 | Ryan Thomas | Portland | 2025-02-14 | Organic | NULL |
| 7 | Priya Murphy | Bristol | 2025-02-25 | Organic | NULL |
| 8 | Chloe Wilson | London | 2025-03-03 | Paid Social | 2 |
| 9 | Amelia Evans | Manchester | 2025-03-06 | Paid Social | 2 |
| 10 | Jack Wilson | Seattle | 2025-03-15 | Paid Social | 2 |
| 11 | Grace Campbell | Austin | 2025-03-17 | Organic | NULL |
| 12 | Ava Lewis | Austin | 2025-03-29 | 3 | |
| 13 | Ruby Murphy | Leeds | 2025-03-30 | Affiliate | 4 |
| 14 | Samuel Khan | Atlanta | 2025-04-05 | Affiliate | 4 |
| 15 | Ruby Miller | Leeds | 2025-04-12 | 3 | |
| 16 | Noah Thomas | London | 2025-04-19 | 3 | |
| 17 | Leo Davies | Denver | 2025-04-26 | Organic | NULL |
| 18 | Leo Wright | Chicago | 2025-05-03 | Organic | NULL |
| 19 | Mia Taylor | Glasgow | 2025-05-08 | Organic | NULL |
| 20 | Liam Robinson | Seattle | 2025-05-12 | 3 | |
| 21 | Ella Evans | Denver | 2025-05-17 | Paid Social | 2 |
| 22 | Daniel Scott | Boston | 2025-05-18 | Organic | NULL |
| 23 | Amelia Wright | Manchester | 2025-05-25 | Paid Search | 1 |
| 24 | Freya Davies | Atlanta | 2025-06-01 | Organic | NULL |
| 25 | Noah Taylor | Boston | 2025-06-09 | 3 | |
| 26 | Ava Miller | Seattle | 2025-06-15 | Paid Social | 6 |
| 27 | Lucas Wilson | Austin | 2025-06-16 | 3 | |
| 28 | Liam Khan | Portland | 2025-06-18 | Paid Social | 6 |
| 29 | Lucas Wright | Glasgow | 2025-06-25 | Paid Social | 6 |
| 30 | Noah Murphy | Denver | 2025-07-06 | Organic | NULL |
| 31 | Grace Khan | Bristol | 2025-07-08 | Paid Search | 5 |
| 32 | Liam Davies | Seattle | 2025-07-10 | Paid Search | 5 |
| 33 | Mason Hall | Seattle | 2025-07-14 | Paid Social | 6 |
| 34 | Ethan Khan | Portland | 2025-07-24 | Paid Social | 6 |
| 35 | Jack Clarke | Leeds | 2025-07-28 | Paid Social | 6 |
| 36 | Ethan Campbell | Seattle | 2025-08-01 | Paid Social | 6 |
| 37 | Harper King | Boston | 2025-08-06 | Organic | NULL |
| 38 | Freya Scott | Manchester | 2025-08-09 | Organic | NULL |
| 39 | Daniel Johnson | Manchester | 2025-08-14 | Paid Social | 6 |
| 40 | Ruby Wilson | Atlanta | 2025-08-19 | Affiliate | 4 |
| 41 | Zoe Khan | Atlanta | 2025-08-29 | Organic | NULL |
| 42 | Oliver Young | Austin | 2025-08-29 | 3 | |
| 43 | Leo King | Glasgow | 2025-09-03 | Organic | NULL |
| 44 | Noah Allen | Bristol | 2025-09-06 | Paid Search | 5 |
| 45 | Oliver Lewis | Austin | 2025-09-15 | Organic | NULL |
| 46 | James Walker | Austin | 2025-09-18 | Paid Search | 5 |
| 47 | Ava Davies | Seattle | 2025-09-19 | Organic | NULL |
| 48 | Leo Allen | London | 2025-09-29 | Organic | NULL |
| 49 | James Hall | Seattle | 2025-09-29 | Paid Search | 5 |
| 50 | Aiden Thomas | Boston | 2025-10-08 | Organic | NULL |
| 51 | Oliver Allen | Austin | 2025-10-11 | Paid Search | 5 |
| 52 | Daniel Clarke | Glasgow | 2025-10-14 | Paid Search | 5 |
| 53 | Liam Harris | Seattle | 2025-10-21 | 3 | |
| 54 | Lucas Campbell | Manchester | 2025-10-24 | Organic | NULL |
| 55 | Freya Brown | London | 2025-10-29 | Paid Search | 5 |
| 56 | Freya Young | Seattle | 2025-11-04 | Organic | NULL |
| 57 | Sophia Lewis | Portland | 2025-11-05 | Paid Search | 5 |
| 58 | Freya Evans | Bristol | 2025-11-18 | Organic | NULL |
| 59 | Leo Patel | London | 2025-11-23 | Paid Search | 5 |
| 60 | Ruby Thomas | Glasgow | 2025-11-23 | Paid Social | 8 |
| 61 | Amelia Taylor | Manchester | 2025-11-25 | 3 | |
| 62 | Liam Murphy | Denver | 2025-12-01 | Paid Social | 8 |
| 63 | Daniel Walker | Chicago | 2025-12-08 | Organic | NULL |
| 64 | Zoe King | Manchester | 2025-12-11 | Organic | NULL |
| 65 | James Clarke | Leeds | 2025-12-15 | Paid Search | 5 |
| 66 | Samuel King | Glasgow | 2025-12-19 | Paid Search | 5 |
| 67 | Leo Miller | Denver | 2025-12-25 | Organic | NULL |
| 68 | Sophia Evans | Portland | 2025-12-26 | Organic | NULL |
| 69 | Sophia Murphy | Austin | 2026-01-06 | Paid Social | 10 |
| 70 | Olivia Khan | Austin | 2026-01-06 | 3 | |
| 71 | James Scott | Leeds | 2026-01-16 | Paid Search | 9 |
| 72 | Noah Smith | Chicago | 2026-01-17 | Paid Search | 9 |
| 73 | Liam Scott | Leeds | 2026-01-23 | Paid Social | 10 |
| 74 | Priya Scott | Portland | 2026-01-26 | Organic | NULL |
| 75 | Jack Davies | Austin | 2026-02-02 | Paid Search | 9 |
| 76 | Priya Campbell | Glasgow | 2026-02-06 | Affiliate | 4 |
| 77 | Olivia Allen | Seattle | 2026-02-07 | Organic | NULL |
| 78 | Lucas Young | Austin | 2026-02-13 | Organic | NULL |
| 79 | Emma Garcia | Bristol | 2026-02-15 | Organic | NULL |
| 80 | Grace Brown | London | 2026-02-20 | Affiliate | 4 |
| 81 | Zoe Taylor | Seattle | 2026-02-25 | Paid Search | 9 |
| 82 | Ava Brown | Manchester | 2026-03-01 | Organic | NULL |
| 83 | Ryan Wilson | Seattle | 2026-03-07 | Organic | NULL |
| 84 | Liam Wright | Austin | 2026-03-11 | 3 | |
| 85 | Olivia Taylor | Seattle | 2026-03-12 | Affiliate | 4 |
| 86 | Ethan Evans | Boston | 2026-03-17 | Organic | NULL |
| 87 | Ella Scott | Boston | 2026-03-19 | Paid Search | 9 |
| 88 | Daniel Hall | Glasgow | 2026-04-01 | Affiliate | 4 |
| 89 | Chloe Thomas | Seattle | 2026-04-05 | Paid Search | 9 |
| 90 | Harper Taylor | Denver | 2026-04-05 | Paid Search | 9 |
| 91 | Ethan King | Austin | 2026-04-11 | Paid Search | 9 |
| 92 | Leo Campbell | Austin | 2026-04-14 | Organic | NULL |
| 93 | Noah Young | Atlanta | 2026-04-19 | Organic | NULL |
| 94 | Noah Johnson | Denver | 2026-04-24 | Paid Search | 9 |
| 95 | Daniel Evans | Glasgow | 2026-04-28 | Affiliate | 4 |
| 96 | Ella Wilson | London | 2026-04-30 | Paid Search | 9 |
| 97 | Grace Allen | Bristol | 2026-05-10 | Affiliate | 4 |
| 98 | Jack Smith | Bristol | 2026-05-11 | Paid Search | 9 |
| 99 | Grace Evans | Portland | 2026-05-13 | Affiliate | 4 |
| 100 | Isla Clarke | London | 2026-05-18 | Paid Search | 9 |
| 101 | Daniel Allen | Seattle | 2026-05-19 | Affiliate | 4 |
| 102 | Zoe Brown | London | 2026-05-25 | Organic | NULL |
| 103 | Daniel Lewis | Atlanta | 2026-06-01 | Organic | NULL |
| 104 | Isla Miller | Seattle | 2026-06-04 | Organic | NULL |
| 105 | Daniel Wright | Manchester | 2026-06-08 | Organic | NULL |
| 106 | Zoe Wright | Glasgow | 2026-06-09 | Organic | NULL |
| 107 | Chloe Walker | Austin | 2026-06-16 | Affiliate | 4 |
| 108 | Chloe Scott | Austin | 2026-06-22 | Paid Search | 9 |
| 109 | Henry Evans | Glasgow | 2026-06-26 | Affiliate | 4 |
| 110 | Ryan Scott | Glasgow | 2026-06-26 | Organic | NULL |
| 111 | Ruby Garcia | Boston | 2026-07-02 | Organic | NULL |
| 112 | Ryan Young | Manchester | 2026-07-04 | Organic | NULL |
| 113 | Priya Walker | Denver | 2026-07-09 | Affiliate | 4 |
| 114 | Chloe Hall | Chicago | 2026-07-14 | Organic | NULL |
| 115 | Jack Campbell | Manchester | 2026-07-19 | Organic | NULL |
| 116 | Harper Scott | Manchester | 2026-07-27 | Paid Search | 12 |
| 117 | Freya Wright | Chicago | 2026-07-28 | Organic | NULL |
| 118 | Jack Hall | Glasgow | 2026-08-03 | Organic | NULL |
| 119 | Chloe Miller | Manchester | 2026-08-07 | 3 | |
| 120 | Oliver Garcia | Boston | 2026-08-09 | Organic | NULL |
| 121 | Daniel King | Portland | 2026-08-15 | Organic | NULL |
| 122 | Ruby Harris | Chicago | 2026-08-18 | Organic | NULL |
| 123 | Ruby Lewis | Portland | 2026-08-25 | Paid Search | 12 |
| 124 | Henry Harris | Manchester | 2026-08-27 | Paid Search | 12 |
| 125 | Ethan Smith | Bristol | 2026-08-31 | 3 | |
| 126 | Emma Lewis | Bristol | 2026-09-03 | 3 | |
| 127 | Zoe Evans | Bristol | 2026-09-07 | Organic | NULL |
| 128 | Ethan Johnson | Bristol | 2026-09-13 | Organic | NULL |
| 129 | Ella Lewis | Denver | 2026-09-19 | Paid Social | 13 |
| 130 | Olivia Robinson | Seattle | 2026-09-20 | Organic | NULL |
| 131 | Amelia King | Boston | 2026-09-22 | 3 | |
| 132 | Oliver Taylor | Glasgow | 2026-09-26 | Paid Search | 12 |
| 133 | James Allen | Seattle | 2026-10-04 | Paid Social | 13 |
| 134 | Henry Khan | Atlanta | 2026-10-05 | Paid Social | 13 |
| 135 | Mia Wright | Manchester | 2026-10-10 | Paid Search | 12 |
| 136 | Mia Johnson | London | 2026-10-16 | Affiliate | 4 |
| 137 | Grace Davies | Leeds | 2026-10-20 | 3 | |
| 138 | Liam Patel | Bristol | 2026-10-22 | Paid Social | 13 |
| 139 | Oliver Wright | Seattle | 2026-10-27 | Organic | NULL |
| 140 | Henry Allen | Seattle | 2026-10-29 | 3 |
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 |
order_items 297 rows, 4 columns
| order_id | product_id | quantity | unit_price |
|---|---|---|---|
| 5001 | 21 | 1 | 19.9 |
| 5001 | 22 | 1 | 9.9 |
| 5002 | 1 | 1 | 89.9 |
| 5002 | 3 | 1 | 24.9 |
| 5002 | 9 | 1 | 24.9 |
| 5003 | 7 | 1 | 49.9 |
| 5004 | 7 | 1 | 49.9 |
| 5004 | 8 | 1 | 19.9 |
| 5005 | 1 | 1 | 89.9 |
| 5006 | 3 | 1 | 24.9 |
| 5007 | 9 | 1 | 24.9 |
| 5008 | 1 | 1 | 89.9 |
| 5008 | 2 | 1 | 14.9 |
| 5008 | 5 | 1 | 34.9 |
| 5009 | 5 | 1 | 34.9 |
| 5010 | 3 | 1 | 24.9 |
| 5011 | 21 | 1 | 19.9 |
| 5012 | 7 | 1 | 49.9 |
| 5013 | 1 | 1 | 89.9 |
| 5014 | 9 | 1 | 24.9 |
| 5015 | 9 | 1 | 24.9 |
| 5016 | 13 | 1 | 79.9 |
| 5017 | 5 | 1 | 34.9 |
| 5018 | 1 | 1 | 89.9 |
| 5019 | 1 | 1 | 89.9 |
| 5019 | 3 | 1 | 24.9 |
| 5020 | 16 | 1 | 99.9 |
| 5021 | 13 | 1 | 79.9 |
| 5022 | 19 | 1 | 29.9 |
| 5023 | 5 | 1 | 34.9 |
| 5024 | 1 | 1 | 89.9 |
| 5025 | 8 | 1 | 19.9 |
| 5026 | 23 | 1 | 39.9 |
| 5027 | 13 | 1 | 79.9 |
| 5028 | 1 | 1 | 89.9 |
| 5029 | 21 | 1 | 19.9 |
| 5029 | 22 | 1 | 9.9 |
| 5030 | 15 | 1 | 27.9 |
| 5031 | 8 | 1 | 19.9 |
| 5032 | 13 | 1 | 79.9 |
| 5033 | 5 | 1 | 34.9 |
| 5034 | 9 | 1 | 24.9 |
| 5035 | 2 | 2 | 14.9 |
| 5036 | 21 | 1 | 19.9 |
| 5037 | 18 | 2 | 9.9 |
| 5038 | 3 | 1 | 24.9 |
| 5039 | 1 | 1 | 89.9 |
| 5039 | 2 | 2 | 14.9 |
| 5040 | 7 | 1 | 49.9 |
| 5041 | 5 | 1 | 34.9 |
| 5042 | 1 | 1 | 89.9 |
| 5043 | 5 | 1 | 34.9 |
| 5044 | 1 | 1 | 89.9 |
| 5044 | 2 | 1 | 14.9 |
| 5045 | 11 | 1 | 29.9 |
| 5046 | 17 | 1 | 119 |
| 5047 | 1 | 1 | 89.9 |
| 5048 | 18 | 1 | 9.9 |
| 5049 | 21 | 1 | 19.9 |
| 5050 | 1 | 1 | 89.9 |
| 5051 | 1 | 1 | 89.9 |
| 5052 | 4 | 1 | 12.9 |
| 5053 | 9 | 1 | 24.9 |
| 5054 | 5 | 1 | 34.9 |
| 5055 | 16 | 1 | 99.9 |
| 5056 | 4 | 2 | 12.9 |
| 5057 | 8 | 1 | 19.9 |
| 5058 | 16 | 1 | 99.9 |
| 5059 | 5 | 1 | 34.9 |
| 5060 | 22 | 1 | 9.9 |
| 5061 | 3 | 1 | 24.9 |
| 5062 | 13 | 1 | 79.9 |
| 5063 | 11 | 1 | 29.9 |
| 5064 | 24 | 1 | 129 |
| 5065 | 7 | 1 | 49.9 |
| 5065 | 8 | 1 | 19.9 |
| 5065 | 14 | 1 | 16.9 |
| 5066 | 1 | 1 | 89.9 |
| 5066 | 2 | 2 | 14.9 |
| 5067 | 16 | 1 | 99.9 |
| 5068 | 1 | 1 | 89.9 |
| 5068 | 2 | 2 | 14.9 |
| 5069 | 5 | 1 | 34.9 |
| 5069 | 8 | 1 | 19.9 |
| 5070 | 7 | 1 | 49.9 |
| 5071 | 14 | 1 | 16.9 |
| 5072 | 1 | 1 | 89.9 |
| 5073 | 5 | 1 | 34.9 |
| 5073 | 8 | 1 | 19.9 |
| 5074 | 16 | 1 | 99.9 |
| 5075 | 5 | 1 | 34.9 |
| 5076 | 1 | 1 | 89.9 |
| 5076 | 3 | 1 | 24.9 |
| 5077 | 4 | 1 | 12.9 |
| 5078 | 10 | 1 | 59.9 |
| 5079 | 15 | 1 | 27.9 |
| 5080 | 21 | 1 | 19.9 |
| 5081 | 1 | 1 | 89.9 |
| 5082 | 4 | 2 | 12.9 |
| 5083 | 10 | 1 | 47.92 |
| 5084 | 1 | 1 | 71.92 |
| 5084 | 3 | 1 | 19.92 |
| 5085 | 11 | 1 | 23.92 |
| 5085 | 19 | 1 | 23.92 |
| 5085 | 20 | 1 | 7.92 |
| 5086 | 11 | 1 | 23.92 |
| 5087 | 23 | 1 | 31.92 |
| 5088 | 10 | 1 | 47.92 |
| 5089 | 11 | 1 | 23.92 |
| 5090 | 7 | 1 | 39.92 |
| 5091 | 11 | 1 | 23.92 |
| 5092 | 6 | 1 | 10.32 |
| 5093 | 1 | 1 | 71.92 |
| 5093 | 3 | 1 | 19.92 |
| 5094 | 23 | 1 | 31.92 |
| 5095 | 24 | 1 | 103.2 |
| 5096 | 13 | 1 | 63.92 |
| 5097 | 5 | 1 | 27.92 |
| 5098 | 22 | 2 | 7.92 |
| 5099 | 22 | 1 | 7.92 |
| 5100 | 5 | 1 | 27.92 |
| 5100 | 6 | 2 | 10.32 |
| 5101 | 5 | 1 | 27.92 |
| 5101 | 6 | 1 | 10.32 |
| 5102 | 23 | 1 | 31.92 |
| 5103 | 6 | 1 | 10.32 |
| 5103 | 16 | 1 | 79.92 |
| 5104 | 21 | 1 | 15.92 |
| 5105 | 22 | 2 | 9.9 |
| 5106 | 1 | 1 | 89.9 |
| 5106 | 9 | 1 | 24.9 |
| 5107 | 11 | 1 | 29.9 |
| 5108 | 7 | 1 | 49.9 |
| 5108 | 19 | 1 | 29.9 |
| 5108 | 20 | 1 | 9.9 |
| 5109 | 1 | 1 | 89.9 |
| 5109 | 2 | 1 | 14.9 |
| 5110 | 5 | 1 | 34.9 |
| 5111 | 10 | 1 | 59.9 |
| 5112 | 13 | 1 | 79.9 |
| 5113 | 14 | 1 | 16.9 |
| 5114 | 21 | 1 | 19.9 |
| 5115 | 1 | 1 | 89.9 |
| 5116 | 6 | 2 | 12.9 |
| 5117 | 1 | 1 | 89.9 |
| 5118 | 21 | 1 | 19.9 |
| 5119 | 10 | 1 | 59.9 |
| 5120 | 18 | 2 | 9.9 |
| 5121 | 17 | 1 | 119 |
| 5122 | 9 | 1 | 24.9 |
| 5123 | 13 | 1 | 79.9 |
| 5124 | 20 | 1 | 9.9 |
| 5125 | 1 | 1 | 89.9 |
| 5125 | 2 | 1 | 14.9 |
| 5126 | 7 | 1 | 49.9 |
| 5127 | 21 | 1 | 19.9 |
| 5128 | 4 | 1 | 12.9 |
| 5129 | 11 | 1 | 29.9 |
| 5130 | 10 | 1 | 59.9 |
| 5131 | 1 | 1 | 89.9 |
| 5132 | 8 | 1 | 19.9 |
| 5133 | 21 | 1 | 19.9 |
| 5133 | 22 | 1 | 9.9 |
| 5134 | 23 | 1 | 39.9 |
| 5135 | 12 | 1 | 44.9 |
| 5136 | 13 | 1 | 79.9 |
| 5137 | 13 | 1 | 79.9 |
| 5137 | 14 | 1 | 16.9 |
| 5137 | 23 | 1 | 39.9 |
| 5138 | 7 | 1 | 49.9 |
| 5139 | 5 | 1 | 34.9 |
| 5139 | 6 | 1 | 12.9 |
| 5140 | 19 | 1 | 29.9 |
| 5140 | 21 | 1 | 19.9 |
| 5141 | 8 | 1 | 19.9 |
| 5142 | 8 | 1 | 19.9 |
| 5143 | 4 | 1 | 12.9 |
| 5143 | 22 | 1 | 9.9 |
| 5144 | 1 | 1 | 89.9 |
| 5144 | 2 | 1 | 14.9 |
| 5145 | 5 | 1 | 34.9 |
| 5146 | 13 | 1 | 79.9 |
| 5146 | 15 | 1 | 27.9 |
| 5147 | 9 | 1 | 24.9 |
| 5148 | 5 | 1 | 34.9 |
| 5149 | 5 | 1 | 34.9 |
| 5150 | 4 | 2 | 12.9 |
| 5151 | 22 | 1 | 9.9 |
| 5152 | 17 | 1 | 119 |
| 5153 | 3 | 1 | 24.9 |
| 5154 | 19 | 1 | 29.9 |
| 5155 | 7 | 1 | 49.9 |
| 5156 | 1 | 1 | 89.9 |
| 5156 | 4 | 1 | 12.9 |
| 5157 | 3 | 1 | 24.9 |
| 5158 | 11 | 1 | 29.9 |
| 5159 | 13 | 1 | 79.9 |
| 5160 | 11 | 1 | 29.9 |
| 5161 | 11 | 1 | 29.9 |
| 5162 | 19 | 1 | 29.9 |
| 5163 | 12 | 1 | 44.9 |
| 5164 | 24 | 1 | 129 |
| 5165 | 4 | 2 | 12.9 |
| 5165 | 19 | 1 | 29.9 |
| 5166 | 5 | 1 | 34.9 |
| 5166 | 8 | 1 | 19.9 |
| 5167 | 2 | 1 | 14.9 |
| 5168 | 5 | 1 | 34.9 |
| 5169 | 24 | 1 | 129 |
| 5170 | 17 | 1 | 119 |
| 5170 | 18 | 3 | 9.9 |
| 5171 | 3 | 1 | 24.9 |
| 5172 | 12 | 1 | 44.9 |
| 5173 | 3 | 1 | 24.9 |
| 5173 | 24 | 1 | 129 |
| 5174 | 16 | 1 | 99.9 |
| 5175 | 24 | 1 | 129 |
| 5176 | 7 | 1 | 49.9 |
| 5177 | 21 | 1 | 19.9 |
| 5178 | 1 | 1 | 89.9 |
| 5178 | 4 | 1 | 12.9 |
| 5179 | 1 | 1 | 89.9 |
| 5179 | 2 | 2 | 14.9 |
| 5180 | 18 | 3 | 9.9 |
| 5181 | 4 | 1 | 12.9 |
| 5182 | 16 | 1 | 99.9 |
| 5183 | 24 | 1 | 129 |
| 5184 | 3 | 1 | 24.9 |
| 5185 | 16 | 1 | 99.9 |
| 5186 | 17 | 1 | 119 |
| 5186 | 23 | 1 | 39.9 |
| 5187 | 7 | 1 | 49.9 |
| 5187 | 8 | 1 | 19.9 |
| 5187 | 12 | 1 | 44.9 |
| 5188 | 23 | 1 | 39.9 |
| 5189 | 21 | 1 | 19.9 |
| 5190 | 7 | 1 | 49.9 |
| 5191 | 17 | 1 | 119 |
| 5191 | 18 | 3 | 9.9 |
| 5192 | 5 | 1 | 34.9 |
| 5193 | 5 | 1 | 34.9 |
| 5194 | 13 | 1 | 79.9 |
| 5195 | 14 | 2 | 16.9 |
| 5196 | 8 | 1 | 19.9 |
| 5197 | 15 | 1 | 27.9 |
| 5198 | 16 | 1 | 99.9 |
| 5199 | 19 | 1 | 29.9 |
| 5200 | 17 | 1 | 119 |
| 5201 | 1 | 1 | 89.9 |
| 5201 | 4 | 1 | 12.9 |
| 5202 | 1 | 1 | 89.9 |
| 5203 | 5 | 1 | 34.9 |
| 5203 | 6 | 1 | 12.9 |
| 5204 | 15 | 1 | 27.9 |
| 5205 | 12 | 1 | 44.9 |
| 5206 | 10 | 1 | 59.9 |
| 5206 | 11 | 1 | 29.9 |
| 5207 | 1 | 1 | 89.9 |
| 5207 | 4 | 1 | 12.9 |
| 5207 | 23 | 1 | 39.9 |
| 5208 | 13 | 1 | 79.9 |
| 5208 | 14 | 2 | 16.9 |
| 5209 | 16 | 1 | 99.9 |
| 5210 | 2 | 2 | 14.9 |
| 5211 | 21 | 1 | 19.9 |
| 5212 | 2 | 2 | 14.9 |
| 5212 | 6 | 1 | 12.9 |
| 5213 | 19 | 1 | 29.9 |
| 5214 | 2 | 2 | 14.9 |
| 5215 | 3 | 1 | 24.9 |
| 5216 | 1 | 1 | 89.9 |
| 5217 | 21 | 1 | 19.9 |
| 5218 | 13 | 1 | 79.9 |
| 5218 | 14 | 1 | 16.9 |
| 5219 | 1 | 1 | 89.9 |
| 5220 | 12 | 1 | 44.9 |
| 5221 | 1 | 1 | 89.9 |
| 5222 | 1 | 1 | 89.9 |
| 5223 | 1 | 1 | 89.9 |
| 5224 | 4 | 2 | 12.9 |
| 5225 | 7 | 1 | 49.9 |
| 5226 | 3 | 1 | 24.9 |
| 5227 | 15 | 1 | 27.9 |
| 5228 | 19 | 1 | 29.9 |
| 5229 | 9 | 1 | 24.9 |
| 5230 | 9 | 1 | 24.9 |
| 5231 | 9 | 1 | 24.9 |
| 5232 | 7 | 1 | 49.9 |
| 5233 | 2 | 1 | 14.9 |
| 5234 | 3 | 1 | 24.9 |
| 5235 | 5 | 1 | 34.9 |
| 5236 | 5 | 1 | 34.9 |
| 5237 | 10 | 1 | 59.9 |
| 5237 | 11 | 1 | 29.9 |
| 5238 | 8 | 1 | 19.9 |
| 5239 | 1 | 1 | 89.9 |
| 5239 | 2 | 1 | 14.9 |
products 24 rows, 5 columns
| product_id | name | category | price | unit_cost |
|---|---|---|---|---|
| 1 | Running shoes | Running | 89.9 | 48 |
| 2 | Running socks, 3 pairs | Running | 14.9 | 5.2 |
| 3 | Running shirt | Running | 24.9 | 10.5 |
| 4 | Water bottle 750 ml | Accessories | 12.9 | 4.1 |
| 5 | Yoga mat | Fitness | 34.9 | 14 |
| 6 | Cork yoga block | Fitness | 12.9 | 4.8 |
| 7 | Dumbbells, pair | Fitness | 49.9 | 22 |
| 8 | Resistance bands, set of 3 | Fitness | 19.9 | 6 |
| 9 | Foam roller | Fitness | 24.9 | 9 |
| 10 | Bike helmet | Cycling | 59.9 | 27 |
| 11 | Bike light set | Cycling | 29.9 | 11.5 |
| 12 | Cycling jersey | Cycling | 44.9 | 19 |
| 13 | Hiking backpack 30 l | Outdoor | 79.9 | 36 |
| 14 | Hiking socks | Outdoor | 16.9 | 6.1 |
| 15 | Headlamp | Outdoor | 27.9 | 10.8 |
| 16 | Rain jacket | Outdoor | 99.9 | 46 |
| 17 | Tennis racket | Ball sports | 119 | 58 |
| 18 | Tennis balls, can of 4 | Ball sports | 9.9 | 3.4 |
| 19 | Training ball, size 5 | Ball sports | 29.9 | 11 |
| 20 | Ball pump | Ball sports | 9.9 | 3 |
| 21 | Swim goggles | Swimming | 19.9 | 6.5 |
| 22 | Swim cap | Swimming | 9.9 | 2.6 |
| 23 | Sports bag | Accessories | 39.9 | 15 |
| 24 | Heart rate watch | Accessories | 129 | 72 |
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.
How it works
Now five tables come together (see joining multiple tables): the CTE, customers for the channel, orders for date and status, order_items for quantity and price, and products for unit cost. After the joins every order line is a row, so the average per customer is SUM(…) / COUNT(DISTINCT f.customer_id). AVG would average over order lines.
Gross margin subtracts the unit cost from every selling price. What is left has to cover advertising, shipping, staff and, in the end, profit. That makes it the right figure to compare with CAC. Black Friday discounts are already in the unit_price of the order lines, so they are handled automatically.
In the result, Email and Paid Search lead on margin with around 74 per customer, while Paid Social comes to 37.19. Next to the cost per new customer from case 2, the Black Friday paid social campaign at 115 per new customer does not look good, while paid search in the second half of 2025 at 35 does. With 4 to 18 customers per channel, treat this as a pointer, not as proof.
Common mistakes
No window
Adding up every order gives January 2025 customers almost two years and October 2025 customers just over one. The exercise says: "Columns and row count match, but not every value."
Less-than-or-equal at the end of the window
"Up to, but not including, the same day 12 months later" means <. With <=, an order placed exactly on the anniversary counts too. The visible data has none, the hidden data does; the exercise then tells you the result is only right with this data.
First order including cancellations
Without a status filter in the CTE, the window starts at a cancelled order. Two customers whose first completed order came after October 2025 slip into the group: 52 rows instead of 50.
AVG over order lines
In task 2, AVG(quantity * unit_price) gives the average per order line, not per customer. The values come out far too small.
Check your result
- Task 1: 50 customers, 5665.98 in revenue during their first 12 months, 113.32 on average. The highest value is 344.4 (customer 2).
- Task 2: customers per channel 4, 8, 18, 10 and 10, adding up to 50. Paid Search: revenue_12m 135.79 and margin_12m 73.82.
- Cross-check: customers times revenue_12m, added up across all channels, comes back to roughly 5665.98.
In MySQL, PostgreSQL and SQL Server
The end of the window is DATE_ADD(first_order, INTERVAL 12 MONTH) in MySQL, DATEADD(month, 12, first_order) in SQL Server and first_order + interval '12 months' in PostgreSQL. They handle missing days differently from SQLite: according to their documentation, MySQL and SQL Server move a day that does not exist in the target month to the last day of that month. SQLite rolls over into the following month by default, as the example above shows.
FAQ
Is this the "real" CLV?
It is a historical customer value over a fixed window. Predictive models also estimate how long customers will stay. For comparing channels and campaigns, the historical value is often enough, and everyone on the team can follow how it was calculated.
Why gross margin rather than revenue?
A customer who spends 100 is worth 50 at a 50% margin and 20 at a 20% margin. Only the margin tells you how much you can afford to spend on winning that customer.
How do I compare customer value and CAC properly?
On the same basis: customers from the same period, costs from the same period, and gross margin instead of revenue. If a channel's margin per customer is above its CAC, the store makes money on those customers within the window.