CASE STATEMENT IN SQL WITH 3 EXAMPLES | SQL TUTORIAL FOR BEGINNERS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back to my channel in today's video we are going to study about case statement in sql so case statement is basically control statements so they are like multiple if then else statement so let's see the syntax over here so here we have written case and then we have when condition number one then result number one will be printed when condition number two then result number two will be printed when condition number n then result number n will be printed or else some result will be printed and end so we'll understand this better with an example it is like multiple if then else statements only so basically if condition number one is true then result one will be printed or else else if condition number two is true then result number two will be printed else else if condition number n is true then result number n will printer else if nothing is true out of the out of these conditions then this will be printed so if no condition is true then it returns the value in else clause so this is case multiple if then else statement so we'll see three examples so let's check the first one so here as we can see select customer customer name case when payment is greater than thousand then it will print or it will give the output as payment is greater than thousand when payment is less than thousand then payment is less than thousand will be printed else payment is equal to thousand so this is just an example so this is how case statements are used and then we'll end like this end as payment tax now you can as is used as an allies so you can ignore this as well but if you want to give a particular name to this you can use alice's ass so customer or customer name or payment these are column names from a table so what this particular query will do is it will select select basically means printing so it will print customer so the customer as you can see over the output customer will be printed customer customer will be printed then customer name will be printed and then case when when payment is greater than thousand now whenever the payment will payment is another column which we are not printing so hence it will not be it will not be shown in the output so when payment is greater than thousand then payment is greater than 1000 this should be printed okay and all of this has an allies payment tax so the column name will be payment tax a payment tax so this is what allies does so customer customer name and this entire thing has an allies payment tax so payment taxes will be the column name so and the output and whatever will be printed in these columns will be this one of the uh one of the one of these so whichever condition will be true that particular thing will be will be will be given as output over here so this is our first example of case now let's see the second example in this second example see your these this is a search condition we are giving some condition like payment is greater than thousand payment is less than thousand or it is equal to thousand and we are giving we are basically giving some condition but over here it's just case value so what what we're doing over here is the same example the same thing select customer customer name whatever all of that and then case gender so what is gender gender is another column name now when m we are not writing any condition aware we can also write this layer right like write this as when gender is equal to m then male when gender is equal to f then female and then we'll end it we can do that as well but these are the two ways how you can write case statements so this is this is how we can write we'll we'll write the column name over your case gender when and directly we'll write the value over here i hope this is clear so the output will be exactly the same but instead of this your the column name will be gender because we have not given an analysis and uh and instead of m and f we print male female the entire world let's see one last example where we are using this case statement in an update class okay so update employees employees the table name set update basically for update we have update set where so update employees set rating rating is another column name now rating we are going to change we are going to update this value rating we are going to change this and then is equal to case now whatever is true out of the two out of all these will be the output over here and that will be the value of rating and that will be changed that value will be updated in the table employees i hope that is clear so as you can see this is the case case statement and it has three when uh events in it so when rate is less than three then you have to print something when rate is equal to three then something when rate is greater than three then something and then we're gonna end it so this is how we can use case inside an update i hope the video was clear so in case you like the video don't don't forget to subscribe to the channel thank you
Info
Channel: Crack Concepts
Views: 19,016
Rating: 4.8969955 out of 5
Keywords: Case statements in sql, Case statements in mysql, Case statements in tableau, Case statements in oracle, Case statements in sql server, Case statements in sql hindi, Case statement in sql, Case statement in mysql
Id: Nn6aFDhvhUI
Channel Id: undefined
Length: 5min 22sec (322 seconds)
Published: Mon Aug 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.