quantity * unit_price. Return category and total_sales, highest first.Use these exact table and column names in your query. Open Schema & Data under the editor to preview sample rows.
customers
5 columns
customer_idINTEGERnameTEXTcityTEXTcountryTEXTsignup_dateDATE
products
4 columns
product_idINTEGERproduct_nameTEXTcategoryTEXTpriceREAL
orders
5 columns
order_idINTEGERcustomer_idINTEGERorder_dateDATEamountREALstatusTEXT
order_items
4 columns
order_idINTEGERproduct_idINTEGERquantityINTEGERunit_priceREAL
payments
5 columns
payment_idINTEGERorder_idINTEGERmethodTEXTamountREALpaid_dateDATE
employees
6 columns
employee_idINTEGERnameTEXTdepartmentTEXTmanager_idINTEGERsalaryREALhire_dateDATE
order_items joined to products
category | total_sales Furniture | ... Electronics | ...
Multiply quantity by unit_price per line, join to products for the category, then sum per category.
Join order_items to products on product_id.
SUM(quantity * unit_price) grouped by category.
Try it yourself first — you learn more from a struggle than a spoiler.
SELECT p.category, SUM(oi.quantity * oi.unit_price) AS total_sales
FROM order_items oi
JOIN products p ON p.product_id = oi.product_id
GROUP BY p.category
ORDER BY total_sales DESC;
customers5 colscustomer_idINTEGERnameTEXTcityTEXTcountryTEXTsignup_dateDATE| customer_id | name | city | country | signup_date |
|---|---|---|---|---|
| 101 | Rahul | Delhi | India | 2023-01-12 |
| 102 | Aman | Mumbai | India | 2023-02-03 |
| 103 | Sara | Bengaluru | India | 2023-02-20 |
products4 colsproduct_idINTEGERproduct_nameTEXTcategoryTEXTpriceREAL| product_id | product_name | category | price |
|---|---|---|---|
| 1 | Wireless Mouse | Electronics | 799 |
| 2 | Office Chair | Furniture | 5499 |
| 3 | Notebook | Stationery | 149 |
orders5 colsorder_idINTEGERcustomer_idINTEGERorder_dateDATEamountREALstatusTEXT| order_id | customer_id | order_date | amount | status |
|---|---|---|---|---|
| 1001 | 101 | 2024-01-05 | 1598 | Delivered |
| 1002 | 102 | 2024-01-11 | 5499 | Delivered |
| 1003 | 101 | 2024-02-02 | 149 | Cancelled |
order_items4 colsorder_idINTEGERproduct_idINTEGERquantityINTEGERunit_priceREAL| order_id | product_id | quantity | unit_price |
|---|---|---|---|
| 1001 | 1 | 2 | 799 |
| 1002 | 2 | 1 | 5499 |
| 1004 | 3 | 5 | 149 |
payments5 colspayment_idINTEGERorder_idINTEGERmethodTEXTamountREALpaid_dateDATE| payment_id | order_id | method | amount | paid_date |
|---|---|---|---|---|
| 5001 | 1001 | UPI | 1598 | 2024-01-05 |
| 5002 | 1002 | Card | 5499 | 2024-01-11 |
| 5003 | 1005 | UPI | 999 | 2024-03-02 |
employees6 colsemployee_idINTEGERnameTEXTdepartmentTEXTmanager_idINTEGERsalaryREALhire_dateDATE| employee_id | name | department | manager_id | salary | hire_date |
|---|---|---|---|---|---|
| 1 | Meera | Analytics | NULL | 180000 | |
| 2 | Rohit | Analytics | 1 | 95000 | |
| 3 | Neha | Engineering | 1 | 120000 |