There is a query that finds the maximum circulation of newspapers produced, it works:

SELECT MAX(SUM(COUNT)) FROM DELIVERY, NEWSPAPER WHERE DELIVERY.IDNEWSPAPERKEY=NEWSPAPER.IDNEWSPAPER GROUP BY NEWSPAPER.IDNEWSPAPER 

I need to pull out the second parameter, for example the ID of the newspaper with the maximum circulation, if I add another parameter as in the query below:

  SELECT IDNEWSPAPER, MAX(SUM(COUNT)) FROM DELIVERY, NEWSPAPER WHERE DELIVERY.IDNEWSPAPERKEY=NEWSPAPER.IDNEWSPAPER GROUP BY NEWSPAPER.IDNEWSPAPER 

the error takes off:

 not a single-group group function 

Tell me how to solve this problem?

1 answer 1

  1. It is not clear why the first query works, and what it does.
  2. If you are looking for the maximum by ID, what ID do you want to see? Let it be for now:
 SELECT IDNEWSPAPER, SUM(COUNT) FROM DELIVERY, NEWSPAPER WHERE DELIVERY.IDNEWSPAPERKEY=NEWSPAPER.IDNEWSPAPER GROUP BY NEWSPAPER.IDNEWSPAPER having SUM(COUNT) >= ALL(SELECT SUM(COUNT) FROM DELIVERY, NEWSPAPER WHERE DELIVERY.IDNEWSPAPERKEY=NEWSPAPER.IDNEWSPAPER GROUP BY NEWSPAPER.IDNEWSPAPER );