Untitled

 avatar
unknown
plain_text
a year ago
1.8 kB
11
Indexable
02/02/2024
------------------------------------------------------

Having clause:
having clause is used for filter the records based on aggregate function and grouping.
having clause is used for only select.

syntax:
select column() from tablename group by columnname having condition.
ex:
select count(*),grade from customer group by grade having count(*)>2;

select count(*),grade from customer group by grade  having count(*)>2;
select count(*),grade from customer where city in ("New York","Berlin") group by grade  having count(*)>2;


when we use having,where,group by,order by clause in onme query 
then the sequence is 
1.where
2.group by
3.having
4.order by

syntax: select column() from tablename
where condition
group by column 
having condition
order by columnname

ex:
select  grade, count(*)  from customer  where city in ("New York","Berlin") group by grade  having count(*)>=2 order by count(*) ;



exa: write a sql query to grade of customer table must be 100
 average of amt for each group of city must be mor tahn 500

solu:-select city, avg(amt) from customer where grade=100
group by city having avg(amt)>500;

-------------------------------------------------------------------------------------------------------------
Update:-
update statement is used to modify the existing records in the table;
syntax:
update table_name set columnname1=value1,columnanme2=value2,.....
where condition
ex:-update employee1 set city="satara" where id=2;
if you are not write where condi in update statement then all records in the table will be updated.
update employee1 set city="nagpur";

-------------------------------------------------------------------------------------------------------------------
SET SQL_SAFE_UPDATES = 0;






Leave a Comment