playground write SQL freely · no grades
SQL Playground
Write SQL against any Runtime dataset. Keep several queries side by side; they're saved in this browser. Nothing here affects course progress.
Two years of real invoice lines from a UK online gift wholesaler: customers, products, sales, cancellations and returns, with modeled payments and customer segment history.
147,608 rows8 tables2009-12 – 2011-12
tables
Open a table to see what one row means, its columns and keys, and a preview. Start from orders: it is the dataset's central table.
categories17 rows · 3 columns
One product category (for example Christmas or Kitchen). Products are grouped into these from their descriptions.
- category_id
Category key
- category_name
Category label
- department
Broader group of categories; Non-merchandise covers fees and accounting adjustments
products5,304 rows · 6 columns
One product in the catalog (one stock code). Some products never appear on invoices in this sample.
- stock_code
Product code; letter codes often mark fees, samples, or adjustments
- description
Usual product name; NULL if the source never described this code
- category_id
Category for this product; NULL if it has no description
- list_price
Typical sale price in GBP; NULL if never sold at a positive price
- first_sold_at
First time this product appeared on any invoice
- is_merchandise
1 for goods, 0 for postage, fees, samples, and adjustments
customers848 rows · 4 columns
One known customer. Anonymous (walk-in) invoices have no matching customer row.
- customer_id
Customer number from the source
- country
Country on the customer’s first invoice
- region
United Kingdom, Europe, or Rest of World
- first_order_at
Time of the customer’s first invoice
orders6,722 rows · 6 columns
One invoice: a sale, a cancellation (credit note), or an accounting adjustment.
- order_id
Invoice key
- invoice_no
Source invoice number; C = cancellation, A = adjustment
- customer_id
Customer; NULL for anonymous invoices
- ordered_at
Invoice time
- country
Delivery country on the invoice
- order_type
sale, cancellation, or adjustment
order_items125,613 rows · 7 columns
One line on an invoice. Cancellation lines use negative quantities.
- order_item_id
Line key
- order_id
Invoice this line belongs to
- line_number
Position on the invoice, starting at 1
- stock_code
Product code
- description
Text printed on this line; can differ from the catalog name
- quantity
Units sold; negative on cancellations and stock adjustments
- unit_price
Price per unit in GBP
payments5,423 rows · 6 columns
One payment attempt for a sale invoice. Payments are modeled; the original source has no payment ledger.
- payment_id
Payment attempt key
- order_id
Sale invoice being paid
- paid_at
When the attempt happened
- method
card, bank_transfer, paypal, or account_credit
- amount
Attempted amount in GBP
- status
captured or failed; only captured attempts count as paid
returns1,996 rows · 6 columns
One cancelled invoice line, linked to the earlier sale it reverses when that sale is in the data.
- return_id
Return key
- order_item_id
The cancellation line being returned
- original_order_id
Earlier sale of the same product to the same customer; NULL if none is found
- quantity_returned
Units returned (positive)
- refund_amount
Credit value in GBP
- returned_at
When the cancellation invoice was issued
customer_history1,685 rows · 7 columns
One version of a customer’s segment and country over time. A new row starts when either changes.
- history_id
Version key
- customer_id
Customer
- segment
occasional, regular, or key_account based on recent net sales
- country
Country for this version
- valid_from
First date this version applies
- valid_to
First date it no longer applies; NULL if this is the current version
- is_current
1 if this is the customer’s current version
relationships
How to join these tables. Left column matches the right column.
- products.category_id joins to categories.category_id
- orders.customer_id joins to customers.customer_id
- order_items.order_id joins to orders.order_id
- order_items.stock_code joins to products.stock_code
- payments.order_id joins to orders.order_id
- returns.order_item_id joins to order_items.order_item_id
- returns.original_order_id joins to orders.order_id
- customer_history.customer_id joins to customers.customer_id