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

I have a SUM function in my SELECT but don't want it to show

I want to see the companies which deliver the most sold items in my DB.

Currently i have this Code:

SELECT L."Firma", SUM("B"."Anzahl")
FROM "Bestelldetails" B, "Artikel" A, "Lieferanten" L
WHERE L."Lieferanten-Nr" = A."Lieferanten-Nr"
AND A."Artikel-Nr" = B."Artikel-Nr"
GROUP BY L."Firma"
ORDER BY 2 DESC

The Output that i get:

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

Firma 2
Company 1 2756
Company 2 2377
Company 3 2063
…many more… ..XXX..

The Output that i want:

Firma
Company 1
Company 2
Company 3
…many more…

Code with output as image

But i don’t want the row with the number 2 to show. I just want the Company-Names to show. How would i do so?

>Solution :

Simply ORDER BY the SUM():

SELECT L."Firma"
FROM "Bestelldetails" B
JOIN "Artikel" A
  ON A."Artikel-Nr" = B."Artikel-Nr"
JOIN "Lieferanten" L
  ON L."Lieferanten-Nr" = A."Lieferanten-Nr"
GROUP BY L."Firma"
ORDER BY SUM("B"."Anzahl") DESC

(Now using proper, explicit JOIN syntax.)

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