Lesson 9 of 13 · 24 min
Revenue reports
By the end of this lesson you can compute item revenue from order lines for a chosen set of order statuses, count orders correctly after combining orders with their lines, and explain the difference between booked revenue and cash received.
Before writing any revenue query, read how the business records money. In Wadi Market's database (see the dataset guide):
- Order value is not stored. An order's item value is the sum of its lines'
quantity * unit_price - discount_amount; the order's total addsorders.shipping_fee. - Status decides whether a sale counts.
cancelledorders never completed;returnedorders were sent back in full and refunded, shipping included.deliveredorders are completed sales, though some had a partial return (inreturns).pending,paidandshippedare still in progress. - Only captured payments are money received.
failedpayments collected nothing;refundedpayments were received and later paid back.
So there is no single “revenue”. Common definitions are gross booked sales (all orders placed), delivered item revenue (completed sales), net revenue (completed sales minus partial refunds) and cash received (captured payments). A good report names its definition.
This lesson, its 4 graded exercises and every other Members lesson in SQL Quest come with a Formula Quest membership that includes SQL (Single Quest with SQL selected, Quest Trio including SQL, or Quest Unlimited), or with SQL access from your organization.
Free to everyone: all of SQL Foundations and Retrieving and Filtering Data, the first lesson of every track, the playground, the dataset library and the SQL reference. See free lessons