Having
SQL HAVING
HAVING is used in select similar like WHERE or when the state of a select uses an aggregate function.
Syntax
SELECT name_of_column, function(name_of_column)
FROM name_of_table
GROUP BY name_of_column
HAVING function(name_of_column) operator value
Example
Orders
ID | NAME | PRICE |
---|---|---|
1 | Learn Python | 45 |
2 | MySQL Tutorial | 32 |
3 | PHP examples | 24 |
4 | Learn SQL | 32 |
2 | MySQL Tutorial | 32 |
SELECT id, name, SUM(price) as total FROM orders GROUP BY id, name HAVING SUM(price) > 32;
Output
ID | NAME | TOTAL |
---|---|---|
1 | Learn Python | 45 |
2 | MySQL Tutorial | 64 |