Guest User

Untitled

a guest
Dec 14th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. id : Auto-Increment
  2. Product : String
  3. Quantity : Number
  4.  
  5. id : Auto-Increment
  6. Product : String
  7. Quantity : Number
  8.  
  9. id | product | quantity
  10. 1 | A | 10
  11. 2 | B | 5
  12. 3 | A | 10
  13. 4 | C | 20
  14. 5 | C | 20
  15. 6 | A | 10
  16. 7 | C | 20
  17. 8 | B | 5
  18. 9 | B | 5
  19.  
  20. id | product | quantity
  21. 1 | A | 50
  22. 2 | B | 10
  23. 3 | C | 80
  24.  
  25. product | quantity_demanded | product_in_stock | rest
  26. A | 30 | 50 | 20
  27. B | 15 | 10 | -5
  28. C | 60 | 80 | 20
  29.  
  30. SELECT s.product, sum(p.quantity) as quantity_demanded,
  31. s.quantity as product_in_stock, s.quantity-sum(p.quantity) AS rest
  32. from product as p inner join stock as s on p.product = s.product
  33. group by s.product, s.quantity;
Add Comment
Please, Sign In to add comment