Return productnames sold (via orderitems) in ALL four quarters of 2025. Table definitions (from the source exercise):
SQLLevel: IntermediateMembership and set logic
Return product_names sold (via order_items) in ALL four quarters of 2025.
Table definitions (from the source exercise):
CREATE TABLE products(product_id INTEGER PRIMARY KEY, product_name TEXT, category TEXT, price REAL);
CREATE TABLE orders(order_id INTEGER PRIMARY KEY, customer_id INTEGER, order_date TEXT, amount REAL, rep_id INTEGER, discount REAL);
CREATE TABLE order_items(item_id INTEGER PRIMARY KEY, order_id INTEGER, product_id INTEGER, quantity INTEGER);
Hints
- Define one output row and the source-table keys.
- Check duplicates, NULLs and the order of filtering and aggregation.
Answer
Approach: QUARTER(order_date) distinct count = 4 per product.
SELECT p.product_name
FROM order_items oi
JOIN orders o ON o.order_id = oi.order_id
JOIN products p ON p.product_id = oi.product_id
WHERE YEAR(o.order_date) = 2025
GROUP BY p.product_id, p.product_name
HAVING COUNT(DISTINCT QUARTER(o.order_date)) = 4;
The source uses SQLite with a MySQL compatibility layer. Date and string functions are dialect dependent; the query is preserved as published.
Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT