Advertisement
Guest User

Query 3 SQL Code

a guest
Apr 30th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. -- Query 3 Solution --
  2. with mat_cost as
  3. (select u.product_id, SUM(u.goes_into_quantity * r.material_standard_cost) as total
  4. from csc342.uses u join csc342.raw_material r on u.material_id = r.material_id
  5. group by u.product_id),
  6.  
  7. product_totals (product_id, product_standard_price) as
  8. (select p.product_id, p.product_standard_price
  9. from csc342.product p)
  10.  
  11. select pt.product_id as "Product ID", p.product_description as "Product Name", TO_CHAr(ABS(pt.product_standard_price - mc.total),'$999,999.99') as "Profit Margin"
  12. from product_totals pt join mat_cost mc on pt.product_id = mc.product_id
  13. join csc342.product p on p.product_id = pt.product_id
  14. order by pt.product_id asc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement