having clause is used with group by. it will apply search condition on the result of group by. generally, in aggregation function is used in having clause. in above table, if we want to display store city and their sells whose total sells is more than 100000 then having clause is used with group by.
syntax :-
select column_name aggregate_function (column_name) from table_name group by column_name having search_condition;
example:-
1.) Give Store_city and sum of sells from store table Store_city wise and also apply condition that sum of sells is greater than or equal 100000.
select Store_city, sum (sells) from store group by store_city having sum (sells) >= 100000;
o/p :-
Store_city | sum (sells) |
Indore | 330000 |
Ujjain | 160000 |
No comments:
Post a Comment