SQL having | Having clause command in sql - sql - sql tutorial - learn sql
- The HAVING clause is used to filter the result set based on the result of an aggregate function.
- It is typically located near or at the end of the SQL statement.
- HAVING is often coupled with the presence of the GROUP BY clause, although it is possible to have a HAVING clause without the GROUP BY clause.
- The brackets around "column_name1" and GROUP BY "column_name1" means that they are optional.
- Note: We may select zero, one, or more columns in addition to the aggregate function. If we do select any column outside of the aggregate function, there is no need for the GROUP BY clause.
- We use the following table for our example.
Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial
- To see only the stores with sales over $1,500, we would type,
sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial
- Total sales for both San Diego and Boston are below $1,500, so the "HAVING SUM(Sales) > 1500" clause filters out these two stores.
- Consider the CUSTOMERS table having the following records.
- Following is an example, which would display a record for a similar age count that would be more than or equal to 2.
- This would produce the following result