Sort by day of the week and time

0

I want to sort by the day of the week and time

The data is coming as follows:

id, dia_hora
1   SEG-10h
2   QUI-11h
3   SEX-09h

query that works when you only get the acronym without time:

SELECT id,dia FROM minhatabela ORDER BY (
   FIELD(dia, 'DOM', 'SEG', 'TER', 'QUA', 'QUI', 'SEX', 'SAB')
)
    
asked by anonymous 14.12.2017 / 19:06

1 answer

0

If the days always come back with 3 characters you can use SUBSTRING()

SELECT id,dia FROM minhatabela ORDER BY ( FIELD(SUBSTRING(dia,1,3), 'DOM', 'SEG', 'TER', 'QUA', 'QUI', 'SEX', 'SAB') , SUBSTRING(dia,3,3) )

    
14.12.2017 / 19:11