Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map values to text "on the fly"

I have the following table:

store | dow |  turnover
------+-----+-----------
 1    |   1 | Eu59.426,00
 1    |   2 | Eu33.074,00
 1    |   5 | Eu38.855,00
 1    |   6 | Eu64.431,00

Please, tell me how to represent days of the week as Sunday, Monday etc. so that I don't have to create a new table with this mapping.

like image 335
Ina Avatar asked Mar 28 '26 09:03

Ina


1 Answers

Try this:

SELECT store, (CASE dow WHEN 1 THEN 'Sunday' 
                        WHEN 2 THEN 'Monday' 
                        WHEN 3 THEN 'Tuesday' 
                        WHEN 4 THEN 'Wednesday' 
                        WHEN 5 THEN 'Thursday' 
                        WHEN 6 THEN 'Friday'  
                        WHEN 7 THEN 'Saturday' 
              END), turnover 
FROM tableA;
like image 54
Saharsh Shah Avatar answered Mar 29 '26 23:03

Saharsh Shah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!