The usage of HAVING clauses in SQL. HAVING users may want to solve a problem when using the SQL language, that is, to limit the output of the result calculated by sum or other set functions. For example, we may only want to see HAVING
One problem that users may want to solve when using the SQL language is to limit the output of the result calculated by sum or other set functions. For example, we may only want to see information about stores with a total sales volume of more than 1500 US dollars in the Store_Information table. then we need to use the HAVING clause. Syntax format:
SELECT "column_name1", SUM ("column_name2 ")
FROM "table_name"
Group by "column_name1"
HAVING (arithematic function condition)
(Group by clause is optional)
Therefore, we can use the following command to achieve the above query purpose:
SELECT store_name, SUM (sales)
FROM Store_Information
Group by store_name
Having sum (sales)> 1500
The query result is displayed as follows:
Store_name SUM (Sales)
Los Angeles $1800
Note:
HAVING clause instead of WHERE clause is used to set query conditions for set functions in SQL. Normally, HAVING clauses are placed at the end of the SQL command.
One problem that http://www.bkjia.com/PHPjc/631065.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631065.htmlTechArticleHAVING users may want to solve when using the SQL language is to limit the output of the result calculated by sum or other set functions. For example, we may only want to see...