Validate a view matches its query
Medium70 pts~25 min
- Views
- EXCEPT
- Set comparison
Practice app · Acme Commerce DB
A real SQL database (SQLite engine) seeded with an e-commerce and HR dataset, with schema browser and query runner.
Your starter code already declares TEST_URL — never hardcode a host.
Objective
Create a customer_revenue view and prove it returns exactly the same rows as the ad-hoc query it encapsulates.
Your task
- 1CREATE VIEW customer_revenue with columns customer_id, name, orders (count of non-cancelled orders) and revenue (ROUND(COALESCE(SUM(total), 0), 2)), LEFT JOINing orders with status <> 'cancelled' in the ON clause.
- 2Write the same logic as a standalone SELECT.
- 3Verify: SELECT COUNT(*) AS mismatches FROM (SELECT customer_id, name, orders, revenue FROM customer_revenue EXCEPT <standalone query>) returns 0.
Acceptance criteria
- customer_revenue returns one row per customer with the expected values
- The last result set shows 0 mismatches
- The script uses CREATE VIEW and EXCEPT
Constraints
- Every run starts from a freshly seeded database, so your script must include its own setup statements.
- Only the last result set of your script is compared, so finish with the verification query.
SQL (SQLite engine) · Database Testing · Joins, views & aggregation