Having clause is used to mention condition in Group based SQL functions, just like WHERE clause .It acts as the same way as does where clause is used:
Syntax for having will be,
- select column_name, function(column_name)
- FROM table_name
- WHERE column_name condition
- GROUP BY column_name
- HAVING function(column_name) condition
Example of HAVING Statement
Consider the following shopping list table.
Suppose we want to find the customer whose previous_balance sum is more than 3000.
We will use the below SQL query for a given database,
- SELECT *
- from shopping list customer
- having sum(previous_balance) > 3000
Result will be,