Rename values in mysql

0

I have the following sql query:

   select nf,status from notas where status = 3

Instead of bringing the number 3 in the sql query result, I wanted to show another message: "complete."

How do I rename?

    
asked by anonymous 29.08.2017 / 15:46

1 answer

1

If you do not have the table with the description of the statuses, you can use case when , otherwise use join with the other table:

select 
    nf,
    status, 
    (case when status = 3 then 'Concluido' else 'Em Aberto' end) as status_descricao
from notas 
where status = 3


select 
    n.nf,
    n.status, 
    ns.descricao
from notas n
inner join notas_status ns on ns.id = n.status
where status = 3
    
29.08.2017 / 15:48