Advertisement
rajeshinternshala

Untitled

Oct 12th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.38 KB | None | 0 0
  1. SELECT p.name AS name,
  2.  
  3.     p.price AS price,
  4.  
  5.     SUM(op.quantity) AS quantity,
  6.  
  7.     SUM(op.quantity * p.price) AS total_price
  8.  
  9. FROM
  10.  
  11.     product p
  12.  
  13. JOIN
  14.  
  15.     product_orders op ON p.id = op.product_id
  16.  
  17. JOIN
  18.  
  19.     ORDER o ON op.order_id = o.id
  20.  
  21. WHERE
  22.  
  23.     o.STATUS = 'Completed'
  24.  
  25. GROUP BY
  26.  
  27.     p.name, p.price
  28.  
  29. ORDER BY
  30.  
  31.     quantity DESC, total_price DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement