Return productids whose monthly revenue (quantity price) rose in BOTH month-over-month steps across 2026 Jan, Feb,…
SQLLevel: AdvancedGaps, islands and streaks
Return product_ids whose monthly revenue (quantity * price) rose in BOTH month-over-month steps across 2026 Jan, Feb, Mar.
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
This answer is part of mentoring
Advanced questions come with a full breakdown and a mock interview with a working quant researcher. The first call is free.
Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT