How to display for which companies the amount for all orders is more than 500?
So displays the total amount for all firms:
SELECT SUM(zakaz.price) AS "Π‘ΡΠΌΠΌΠ° Π·Π°ΠΊΠ°Π·Π°", firma.fname AS "ΠΠ°Π·Π²Π°Π½ΠΈΠ΅ ΡΠΈΡΠΌΡ", COUNT(zakaz.codf) AS "ΠΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ Π·Π°ΠΊΠ°Π·ΠΎΠ²" FROM firma INNER JOIN zakaz ON zakaz.codf = firma.codf GROUP BY firma.fname I try to do this, but it gives an error:
SELECT SUM(zakaz.price) AS "Π‘ΡΠΌΠΌΠ° Π·Π°ΠΊΠ°Π·Π°", firma.fname AS "ΠΠ°Π·Π²Π°Π½ΠΈΠ΅ ΡΠΈΡΠΌΡ", COUNT(zakaz.codf) AS "ΠΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ Π·Π°ΠΊΠ°Π·ΠΎΠ²" FROM firma INNER JOIN zakaz ON zakaz.codf = firma.codf WHERE SUM(zakaz.price) > 500 GROUP BY firma.fname Mistake:
The aggregate expression cannot be used in the WHERE clause unless it is contained in a subquery of the HAVING clause or in the select list, and the column being aggregated is not an external reference.