Problem
Warehouse pick-and-pack operations need to know the total number of physical items in each order before routing it to the right packing station. An order with 20 items goes to a large-box station; one with 2 items goes to an envelope station. This query aggregates all line-item quantities per order so the warehouse management system can make that routing decision. Using the order_items table, return order_id and total_items (the sum of all quantities in that order), ordered by order_id.
Schema
order_items
| column | type |
|---|
| id | INTEGER |
| order_id | INTEGER |
| product_id | INTEGER |
| quantity | INTEGER |
| unit_price | NUMERIC |
Sample Data
| id | order_id | product_id | quantity | unit_price |
|---|
| 1 | 101 | 1 | 2 | 9.99 |
| 2 | 101 | 2 | 3 | 49.99 |
| 3 | 102 | 3 | 1 | 79.99 |
| 4 | 103 | 1 | 5 | 9.99 |
| 5 | 103 | 4 | 2 | 14.99 |
Expected Output
| order_id | total_items |
|---|
| 101 | 5 |
| 102 | 1 |
| 103 | 7 |