Overview
Summarize the orders in one row: count them, count those with a coupon and average their totals, knowing exactly which rows NULL leaves out.
- COUNT(*), SUM(), AVG()
- COUNT(column) skips NULL
- ROUND() on an average
Short Course
Aggregates turn many rows into one: COUNT(*), SUM(), AVG(), MIN(),
MAX(). Trap: COUNT(column) skips NULLs, so COUNT(coupon) counts only the
orders that used one, while COUNT(*) counts every row.
SELECT COUNT(*) AS orders, -- every row
COUNT(coupon) AS with_coupon, -- NULLs skipped
MAX(total) AS biggest
FROM orders;
Task
Return one row: the number of orders, the number of orders that used a
coupon, and the average total rounded to 2 decimals. In the database
below, 2 of the 4 orders used a coupon.
Database
Sample data from the first test. The other tests use different rows, so write a query, not a list of answers.
| idINTEGER | couponTEXT | totalREAL |
|---|---|---|
| 1 | SPRING | 40.0 |
| 2 | NULL | 25.5 |
| 3 | VIP | 100.0 |
| 4 | NULL | 12.1 |
Test Suites
Pending
Next
Output