Search code examples
mysqlsqldatetimeselectdayofweek

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.


Solution

  • 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;