Home » SQL Basics » Retrieving Data » Using HAVING

Using HAVING

Using HAVING

Syntax: SELECT “column_name1”, SUM(“column_name2”), “column_name3″,….”column_nameZ” FROM “table_name”
GROUP BY “column_name1”, “column_name3″,….”column_nameZ”
HAVING (arithmetic function condition)

Example: SELECT store_name, SUM(sales) FROM Store_Sales GROUP BY store_name
HAVING SUM(sales) > 1500

In the above example it displays all Stores with thier Sum of Sales which are greater than 1500.
Note: Group by list should contain all columns in the Select List except ones which are used in Arthemitic functions like Sum.

Leave a Reply

Your email address will not be published. Required fields are marked *