Sort by day of the week and time

Asked

Viewed 169 times

0

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

the data are coming as follows:

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

query that works when you receive only the acronyms with no time:

SELECT id,dia FROM minhatabela ORDER BY (
   FIELD(dia, 'DOM', 'SEG', 'TER', 'QUA', 'QUI', 'SEX', 'SAB')
)
  • Two different dice in the same column, wouldn’t it be better to separate that?

  • I think it would be impracticable given the size of the system that is already ready.

1 answer

0


If always the days 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) )

  • worked, I can use 2 field with substring one for the acronym another for time?

  • Yes only separate by "," I already edit

  • thanks man :)

Browser other questions tagged

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