Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple IF on the same column

A stupid question:

I have to group in the same column different if statements. How can I do?

if(string='AAA','A','other'), if(string='BBB','B','other') AS COLUMN 1

Thanks!

like image 853
Doppia L Avatar asked Dec 14 '22 16:12

Doppia L


1 Answers

use case statement

Select
Case 
When string="AAA" then "A_String"
When string="BBB" then "B_String"
When String in ("CCC","DDD") then "C_OR_D_String"
Else "Unknow_String"
End AS String_Class
From My_Table

Hope this helps

like image 183
N.N. Avatar answered Dec 28 '22 05:12

N.N.