Linux SQL statement concise tutorial --- HAVING, concise tutorial --- having

Source: Internet
Author: User

Linux SQL statement concise tutorial --- HAVING, concise tutorial --- having

How can we set conditions for the values produced by functions? For example, we may only need to know which stores have a turnover of more than $1,500. In this case, we cannot useWHERE. What should we do? Fortunately, SQL providesHAVINGAnd we can use this command to achieve this goal.HAVINGClauses are usually at the end of an SQL sentence. AHAVINGClause SQL does not have to includeGROUPClause.HAVINGSyntax:

SELECT "column 1", SUM ("column 2 ")
FROM "table name"
Group by "column 1"
HAVING (function condition );

Note:GROUPClause is not required.

In ourStore_InformationIn this example,

Store_InformationTable

Store_Name Sales Txn_Date
Los Angeles 1500 05-Jan 1999
San Diego 250 07-Jan-1999
Los Angeles 300 08-Jan 1999
Boston 700 08-Jan 1999

We entered,

SELECT Store_Name, SUM (Sales)
FROM Store_Information
Group by Store_Name
Having sum (sales)> 1500;

Result:

Store_Name SUM (Sales)
Los Angeles 1800



Linux testing:




Reprinted, please note: Xiao Liu


Related Article

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.