having group by code example

Example 1: SQL group by having clause

SELECT
    customer_id,
    YEAR (order_date),
    COUNT (order_id) order_count
FROM
    sales.orders
GROUP BY
    customer_id,
    YEAR (order_date)
HAVING
    COUNT (order_id) >= 2
ORDER BY
    customer_id;
Code language: SQL (Structured Query Language) (sql)

Example 2: sql count having

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

Example 3: mysql HAVING

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

Tags:

Sql Example