Write Case Statement on Mysql.

Let’s see how to write case statement on mysql using a example.
let’s you have a table emp on your database like this

Now write the below query code on sql window

SELECT *,
(CASE 
   WHEN salary=3000 
     THEN 'three thousand' 
   WHEN salary = 10000 
     THEN 'Ten Thousand'
   ELSE 'zero' 
  END) AS result_salary
FROM `emp`;

get the result like this

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *