sql >> Base de Datos >  >> RDS >> Mysql

Columna condicional para consulta basada en otras columnas en 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