mysql group by having code example

Example 1: MySQL GROUP BY

SELECT 
    c1, c2,..., cn, aggregate_function(ci)
FROM
    table
WHERE
    where_conditions
GROUP BY c1 , c2,...,cn;

Example 2: sql count having

SELECT COUNT( * ) 
FROM agents 
HAVING COUNT(*)>1; --count is greater than 1

Example 3: MySQL GROUP BY

SELECT Manufacturer, COUNT(*) AS ModelsCount
FROM Products
WHERE Price > 30000
GROUP BY Manufacturer
ORDER BY ModelsCount DESC

Example 4: mysql HAVING

SELECT colonne1, SUM(colonne2)
FROM nom_table
GROUP BY colonne1
HAVING fonction(colonne2) operateur valeur

Tags:

Sql Example