Friday, August 4, 2023

CASE Query in SQL

 CREATE TABLE emp(id int , sal int);



insert into emp values(1,100);

insert into emp values(2,200);

insert into emp values(3,300);

insert into emp values(4,400);

insert into emp values(5,500);

insert into emp values(6,600);

insert into emp values(7,700);

insert into emp values(8,800);

insert into emp values(9,900);

insert into emp values(10,1000);



select * from emp;



Update emp set sal = 

Case  id When '1' THEN sal + 10 

         When '2' THEN sal + 20

       ELSE 

   sal

       END

        WHERE id IN('1', '2');




No comments:

Post a Comment

ADVANCE 2025

 HTML TABLE SCROLL BAR  <style>      .table-container {             width: 100%;             overflow-x: auto; /* Enables horizontal s...