group by and having clause sql code example
Example 1: having keyword sql
Having keyword basically similar to if condition
Only returns true conditions
SELECT FIRST_NAME , COUNT(*)
FROM EMPLOYEES
GROUP BY FIRST_NAME
HAVING COUNT(*) > 1
Example 2: 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)