Hello friends, could you help me, I would like to ask a query on a mysql bd to sort the records for the day of the week in which you are currently
I have these records:
+---------+----------+
| id_cron | day_week |
+---------+----------+
| 126 | 2 |
| 131 | 3 |
| 136 | 4 |
| 1 | 0 |
| 2 | 1 |
| 51 | 5 |
| 3 | 6 |
| 61 | 0 |
| 76 | 0 |
| 36 | 5 |
| 41 | 6 |
| 4 | 0 |
| 5 | 1 |
| 6 | 2 |
| 7 | 4 |
| 8 | 3 |
| 9 | 6 |
| 10 | 0 |
| 141 | 3 |
| 11 | 5 |
| 12 | 6 |
| 13 | 0 |
| 46 | 3 |
| 14 | 4 |
| 15 | 6 |
| 16 | 0 |
| 17 | 5 |
| 18 | 6 |
| 66 | 2 |
| 71 | 3 |
| 19 | 0 |
| 20 | 5 |
| 21 | 6 |
| 96 | 3 |
| 91 | 4 |
| 101 | 2 |
| 106 | 5 |
| 111 | 6 |
| 86 | 2 |
| 81 | 5 |
| 121 | 2 |
| 116 | 4 |
| 31 | 0 |
| 22 | 2 |
| 23 | 3 |
| 24 | 0 |
| 25 | 5 |
| 26 | 6 |
+---------+----------+
Where in the column day_week
2
is Martes
, 3
is Miercoles
, 4
is Jueves
etc
and want to order them by the day number, starting with the day on which we are.
Example:
Today 2017-09-21
is 4
should be in the order 4,5,6,0,1,2,3
asi:
+---------+----------+
| id_cron | day_week |
+---------+----------+
| 7 | 4 |
| 136 | 4 |
| 116 | 4 |
| 91 | 4 |
| 14 | 4 |
| 51 | 5 |
| 20 | 5 |
| 11 | 5 |
| 36 | 5 |
| 25 | 5 |
| 81 | 5 |
| 106 | 5 |
| 17 | 5 |
| 26 | 6 |
| 41 | 6 |
| 111 | 6 |
| 21 | 6 |
| 18 | 6 |
| 15 | 6 |
| 3 | 6 |
| 12 | 6 |
| 9 | 6 |
| 16 | 0 |
| 4 | 0 |
| 76 | 0 |
| 61 | 0 |
| 19 | 0 |
| 31 | 0 |
| 13 | 0 |
| 1 | 0 |
| 24 | 0 |
| 10 | 0 |
| 5 | 1 |
| 2 | 1 |
| 126 | 2 |
| 6 | 2 |
| 121 | 2 |
| 66 | 2 |
| 22 | 2 |
| 101 | 2 |
| 86 | 2 |
| 131 | 3 |
| 96 | 3 |
| 71 | 3 |
| 46 | 3 |
| 8 | 3 |
| 23 | 3 |
| 141 | 3 |
+---------+----------+
and tomorrow if the query is executed 2017-09-22
is 5
should be in the order 5,6,0,1,2,3,4
I was trying with the function WEEKDAY(NOW())+1
but I do not know how to apply it correctly
Thank you very much,
greetings