Editor

Running total of revenue in 2025

Hard · Online shop database · Window functions, WITH (CTE)

For every delivered order placed in 2025, work out the order total (quantity times unit_price, summed over its items) and a running total: the sum of this order and every earlier one in date order.

Return the order id, order_date, the order total and the running total, both rounded to 2 decimals with round, in that order, sorted by order date.

Expected result

idorder_datetotalrunning_total
12025-02-0334.9634.96
22025-02-14220.98255.94
32025-03-0189.5345.44
52025-04-0570.99416.43
62025-04-1882498.43
72025-05-02102.99601.42
82025-05-2778679.42
102025-06-3082.43761.85
112025-07-15119880.85
122025-08-0852.88933.73
132025-08-2144977.73
152025-10-0218.5996.23
162025-10-1993.991090.22
182025-11-28391129.22
192025-12-1259.481188.7
202025-12-20961284.7
The online shop tables

customers: 18 rows, first 5 shown

idnamecitycountrysignup_datephone
1Ravi KumarBengaluruIndia2025-01-12+91 98450 12345
2Emily JohnsonAustinUSA2025-01-25+1 512 555 0142
3Hiroshi SatoOsakaJapan2025-02-08NULL
4Ana SouzaSao PauloBrazil2025-02-19+55 11 91234 5678
5Priya SharmaMumbaiIndia2025-03-03+91 99200 54321

order_items: 40 rows, first 5 shown

idorder_idproduct_idquantityunit_price
111122.99
21933.99
3241189
4216215.99
532189.5

orders: 28 rows, first 5 shown

idcustomer_idorder_datestatus
112025-02-03delivered
222025-02-14delivered
332025-03-01delivered
412025-03-22cancelled
542025-04-05delivered

products: 18 rows, first 5 shown

idnamecategorypricestock
1Wireless MouseElectronics24.99120
2Mechanical KeyboardElectronics89.545
3USB-C HubElectronics3980
4Noise Cancelling HeadphonesElectronics19925
5Intro to StatisticsBooks4860
-- Write your SQL here