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 adds orders.shipping_fee.
  • Status decides whether a sale counts. cancelled orders never completed; returned orders were sent back in full and refunded, shipping included. delivered orders are completed sales, though some had a partial return (in returns). pending, paid and shipped are still in progress.
  • Only captured payments are money received. failed payments collected nothing; refunded payments 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.

Included with a Formula Quest membership

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