Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT p.name AS name,
- p.price AS price,
- SUM(op.quantity) AS quantity,
- SUM(op.quantity * p.price) AS total_price
- FROM
- product p
- JOIN
- product_orders op ON p.id = op.product_id
- JOIN
- ORDER o ON op.order_id = o.id
- WHERE
- o.STATUS = 'Completed'
- GROUP BY
- p.name, p.price
- ORDER BY
- quantity DESC, total_price DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement