Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Coluna condicional para consulta baseada em outras colunas no MySQL

select User_id
,case 
    when (YEAR(DOB) < 1980 AND Job_Title = "manager")   then 'Old Fart'
    when (YEAR(DOB) < 1980 AND Job_Title = "associate") then 'Old Timer'
    when (YEAR(DOB) > 1980 AND Job_Title = "manager")   then 'Eager Beaver'
    when (YEAR(DOB) > 1980 AND Job_Title = "associate") then 'Slacker'
    else 'nobody'
end
as Real_Title 
from users