Home > Backend Development > PHP Tutorial > Usage of HAVING clause in SQL_PHP tutorial

Usage of HAVING clause in SQL_PHP tutorial

WBOY
Release: 2016-07-13 17:02:16
Original
1185 people have browsed it

HAVING
One problem that users may want to solve when using SQL language is to limit the output of sum or other aggregate function operation results. For example, we may only want to see information about stores with total sales of more than $1,500 in the Store_Information data table. In this case, 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 can Select)
Thus, 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 results are displayed as:
store_name SUM(Sales)
Los Angeles $1800
Minor note:
Use the HAVING clause instead of the WHERE clause when setting query conditions for aggregate functions in SQL language. Typically, the HAVING clause is placed at the end of the SQL command


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631065.htmlTechArticleHAVING One problem that users may want to solve when using SQL language is the calculation of sum or other set functions The output of the results is restricted. For example, we might only want to see...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template