group by and having 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