Case for various fields

0

Can I make a query using 1 case for multiple fields? The fields are of type int .

If not, can I do it in php?

Query

select *,
(case (pergunta1,pergunta2)
when 1 then 'Ótimo'
when 2 then 'Bom'
when 3 then 'Regular'
when 4 then 'Ruim'                                                            
END) as pergunta1,pergunta2 from tabela
    
asked by anonymous 07.11.2016 / 11:51

1 answer

1

Yes, but to use this type of case you can not have the fixed value right after the case and the tests must be done in when as follows:

select *,
      (case
         when pergunta1 = 1 and pergunta2 = 1 then 'Ótimo'
         when pergunta1 = 2 and pergunta2 = 2 then 'Bom'
         when pergunta1 = 3 and pergunta2 = 3 then 'Regular'
         when pergunta1 = 4 and pergunta2 = 4 then 'Ruim'
      END) as pergunta1,pergunta2 from tabela
    
07.11.2016 / 11:58