Question from the SQL - Fundamentals test

Write a SQL query to get the order_id and total number of items for each order.

Medium

Given the following 'orders' and 'order_items' tables:

orders:
| order_id | customer_id |
|----------|-------------|
| 1 | 1 |
| 2 | 2 |
| 3 | 1 |

order_items:
| order_item_id | order_id | product_id | quantity |
|---------------|----------|------------|----------|
| 1 | 1 | 1 | 2 |
| 2 | 1 | 2 | 1 |
| 3 | 2 | 1 | 1 |

Which SQL query retrieves the order_id and total number of items for each order?

Author: Vincent CotroStatus: PublishedQuestion passed 1794 times
Edit
3
Community EvaluationsNo one has reviewed this question yet, be the first!