Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

want to find the products total quantity greater than 50

orders table with columns: order_id, product_id, and quantity.

products table with columns: product_id, product_name, and price.

want to find the products total quantity greater than 50

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sample

order_id product_id quantity
1 1 10
2 2 25
3 3 30
4 1 20
5 2 30
6 3 50
product_id product_name price
1 Product 1 100
2 Product 2 200
3 Product 3 300

The expected output

product_name total_quantity
Product 3 50
Product 2 55

in mysql i need sql :i need to query , not able to get result . Help is appreciated

>Solution :

Try this

SELECT product_name, SUM(quantity) AS total_quantity
FROM products
JOIN orders ON product_id = product_id
GROUP BY product_name
HAVING SUM(quantity) > 50;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading