So how do we set the conditions for the values that the function produces? For example, we may only need to know which stores have more than $1,500 turnover. In this case, we cannot use the where directive. What do we do then? Fortunately, SQL provides a having command, and we can use this command to achieve this goal. The HAVING clause is usually at the end of a SQL sentence. A SQL containing a HAVING clause does not necessarily include a GROUP by clause. having the following syntax:
Select "Field 1", SUM ("Field 2")
From "Table name"
GROUP by "Field 1"
Having (function condition);
Note to the reader: the GROUP by clause is not necessarily required.
In the example of our store_information form,
store_information Form
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 enter,
SELECT Store_name, SUM (Sales)
From Store_information
GROUP by Store_name
Having SUM (sales) >;
Results:
Store_name |
SUM (Sales) |
Los Angeles |
1800 |
Linux testing:
Reprint please specify: Xiao Liu
A concise tutorial of SQL statements for Linux---having