Replace number by string in results

Asked

Viewed 89 times

0

I have the following query:

SELECT 
sum(pedidos_lentes.quantidade) AS value, 
pedidos_lentes.solar AS label FROM pedidos 
JOIN pedidos_lentes ON pedidos_lentes.id_pedido = pedidos.id_pedido 
WHERE id_loja = 2
group by pedidos_lentes.solar

The column label returns the values 1 and 0, stored in the database. In the result, it is possible to swap these values for strings?

2 answers

1

Solved:

SELECT 
sum(pedidos_lentes.quantidade) AS value, 
CASE pedidos_lentes.solar WHEN 1 THEN 'Yes' ELSE 'No' END AS label 

FROM pedidos 

JOIN pedidos_lentes ON pedidos_lentes.id_pedido = pedidos.id_pedido 
WHERE id_loja = 2
group by pedidos_lentes.solar

0

Hey, buddy, help yourself:

SELECT 
sum(pedidos_lentes.quantidade) AS value,
CAST(pedidos_lentes.solara as CHAR(1)) AS label,
JOIN pedidos_lentes ON pedidos_lentes.id_pedido = pedidos.id_pedido 
WHERE id_loja = 2
group by pedidos_lentes.solar
  • Thanks, but I fit using CASE.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.