Question

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.

Was it helpful?

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;

OTHER TIPS

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

note: in mysql i think there is no function which can return day name on index value,, DAYNAME('date')-- this is call only for obtaining a dayname for any date;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top