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