Conditional in MySQL

1

I would like to get a string obeying a condition in MySQL. For example I have a table with a column named descritor that is populated with PT or MT , I'd like to get the string Português to PT and Matemática to MT in a query. >

Example:

If descriptor = PT then Português

If descriptor = MT then Matemática

    
asked by anonymous 09.03.2018 / 12:01

1 answer

2

You can use CASE WHEN for this:

SELECT *,
CASE descritor  
    WHEN 'PT' THEN 'Português' 
    WHEN 'MT' THEN 'Matemática'
END AS Disciplina
FROM Tabela
    
09.03.2018 / 12:17