RienSQL
TASK #159 · Hard · Zalando

Top Category by Monthly Revenue

Your brief
Line-item revenue is order_items.quantity × products.price; the month comes from orders.order_date.

Write a query that for every month returns mth (in the 'YYYY-MM' format) and the category with the highest total revenue in that month. Test data excludes the case of two categories with equal revenue. Sort the result by mth.
Expected columnsmth categoryZalando
SQL editor
SQLite
Ctrl / ⌘ + ↵
Result

Write a query and run it to see the results.

Schema
productsproduct_id, product_name, category, price
reviewsreview_id, product_id, user_id, submit_date, stars
inventoryinventory_id, product_id, status, add_date
ordersorder_id, user_id, order_date
order_itemsitem_id, order_id, product_id, quantity