Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- id : Auto-Increment
- Product : String
- Quantity : Number
- id : Auto-Increment
- Product : String
- Quantity : Number
- id | product | quantity
- 1 | A | 10
- 2 | B | 5
- 3 | A | 10
- 4 | C | 20
- 5 | C | 20
- 6 | A | 10
- 7 | C | 20
- 8 | B | 5
- 9 | B | 5
- id | product | quantity
- 1 | A | 50
- 2 | B | 10
- 3 | C | 80
- product | quantity_demanded | product_in_stock | rest
- A | 30 | 50 | 20
- B | 15 | 10 | -5
- C | 60 | 80 | 20
- SELECT s.product, sum(p.quantity) as quantity_demanded,
- s.quantity as product_in_stock, s.quantity-sum(p.quantity) AS rest
- from product as p inner join stock as s on p.product = s.product
- group by s.product, s.quantity;
Add Comment
Please, Sign In to add comment