Having
One problem that users may want to solve in the process of using SQL language is to limit the output of the results of sum or other aggregate functions. For example, we may only want to see information about stores that have a total sales of more than 1500 dollars in the Store_information datasheet, and then we need to use the HAVING clause. The syntax format is:
Select "Column_name1", SUM ("column_name2")
From "table_name"
GROUP by "column_name1"
Having (arithematic function condition)
(GROUP by clause optional)
Therefore, we can use the following command to achieve the purpose of the above query:
SELECT store_name, SUM (sales)
From Store_information
GROUP by Store_name
Having SUM (sales) > 1500
The query results appear as follows:
Store_name SUM (Sales)
Los Angeles $1800
Note
Use a HAVING clause instead of the WHERE clause in the SQL language when setting the query condition of the aggregate function. Usually, the HAVING clause is placed at the end of the SQL command