Decode Analytics

View Original

Having

HAVING filters records that work on summarized GROUP BY results.

HAVING must come after GROUP BY.

WHERE and HAVING clause can be in the same query.

Only the groups that meet the HAVING criteria will be returned.

SQL HAVING Syntax:


SELECT  Column1

FROM Table_Name

Group BY  Column1

Having condition

(Order by Column1 ) -Optional

 

Syntax with Where clause:

 SELECT  Column1

FROM Table_Name

WHERE condition

Group BY  Column1

Having condition

(Order by Column1 ) -Optional

Example:

Lets use the “Products” table to find the sum by product but we only want to return products with a sum over 1500.

See this content in the original post

Results:

See this content in the original post

SQL Tutorial

See this content in the original post