HAVING clause in SQL _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.