PostgreSQL Having

PostgreSQL Having

The PostgreSQL HAVING is used with a GROUP BY clause and returns records where aggregate values meet the specified conditions.

Having syntax

SELECT column_name1, column_name2, function(column_name1)
FROM table_name
GROUP BY column_name1, column_name2
HAVING function(column_name1) operator value

Having example

Goods table

idgood_typenamedescriptionprice
1ACar_1Car 1 description100
2ACar_2Car 2 description200
3ACar_3Car 3 description100
4BBoat_4Boat 4 description500
5BBoat_5Boat 5 description300
6CTrain_1Train 123 description800
SELECT good_type, count(good_type) g_count
FROM goods
GROUP BY good_type
HAVING count(good_type) > 1

Result

good_typeg_count
B2
A3