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

SQL | I want to compare a sum of two or more rows and then make a select statement

So I have this table in MySQL:

datec.masini

enter image description here

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

So, a proprietar (person unique ID) can have one or more cars with a valoare (value $) and I want to show by a SELECT statement all the persons (proprietar) with cars above 190000$.
I tried this but doesn’t work:

SELECT proprietar FROM datec.masini WHERE sum(valoare)>190000

and I want this result:

1990724 5780623

What am I missing here?

>Solution :

One approach, using aggregation:

SELECT proprietar
FROM datec.masini
GROUP BY proprietar
HAVING SUM(valoare) > 190000;
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