If we want to get the result of the sales of those stores which have more than $1300 salary, then we have to use a clause known as WHERE. If we have to use a function related to aggregation then the clause HAVING will be used. The statement which has HAVING as a clause can have a GROUP BY command. The basic structure of HAVING clause is this,
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1"
HAVING (arithmetic function condition)
FROM "table_name"
GROUP BY "column_name1"
HAVING (arithmetic function condition)
It should be cleared that GROUP BY is not necessary clause.
Store_Information
store_name Sales Date
San Diego $1550 Jan-06-2011
San Diego $200 Jan-07-2011
Los Angeles $350 Jan-08-2011
Boston $750 Jan-08-2011
San Diego $1550 Jan-06-2011
San Diego $200 Jan-07-2011
Los Angeles $350 Jan-08-2011
Boston $750 Jan-08-2011
The syntax is
SELECT store_name, SUM(sales)
FROM Store_Information
GROUP BY store_name
HAVING SUM(sales) > 1300
FROM Store_Information
GROUP BY store_name
HAVING SUM(sales) > 1300
Product:
store_name SUM(Sales)
San Diego $1750
San Diego $1750
Leave a Reply