The Shipping Doubled
orders:
| id | cust | shipping |
|---|---|---|
| 1 | A | 10 |
| 2 | B | 20 |
order_items:
| order_id | qty | price |
|---|---|---|
| 1 | 1 | 100 |
| 1 | 2 | 50 |
| 2 | 1 | 30 |
SELECT o.cust,
sum(o.shipping) AS shipping,
sum(i.qty * i.price) AS goods
FROM orders o
JOIN order_items i ON i.order_id = o.id
GROUP BY o.cust;
What are the two rows?
Sign in to answer questions and track your progress
Sign In