mysql,在枚举中排序(滚动)天,从今天开始'

时间:2017-01-11 14:02:30

标签: php mysql sorting enums

我有:

enum('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')<BR>

我希望能够从今天开始排序&#39;或日期(date_format(%a))

有没有办法解决枚举的索引和ROL的种类? (抱歉,那里有老派汇编语言) 或者,首先在PHP中更容易吗? 目前我只是有一个常规的

SORT BY students.day (the enum field)

1 个答案:

答案 0 :(得分:0)

你可以在SQL中这样做:

select * from sortday
order by 
   (myday + DAYOFWEEK(NOW())) MOD 7;

<强>样品

mysql> select * from sortday;
+----+-------+----------------+
| id | myday | val            |
+----+-------+----------------+
|  1 | Mon   | Text from mo   |
|  2 | Tue   | text from Tue  |
|  3 | Wed   | Text from Wed  |
|  4 | Thu   | day Tue        |
|  5 | Fri   | this is friday |
|  6 | Sat   | its sat        |
|  7 | Sun   | ist sunday     |
+----+-------+----------------+
7 rows in set (0,00 sec)

mysql> select * from sortday order by (myday + DAYOFWEEK(NOW())) MOD 7;
+----+-------+----------------+
| id | myday | val            |
+----+-------+----------------+
|  3 | Wed   | Text from Wed  |
|  4 | Thu   | day Tue        |
|  5 | Fri   | this is friday |
|  6 | Sat   | its sat        |
|  7 | Sun   | ist sunday     |
|  1 | Mon   | Text from mo   |
|  2 | Tue   | text from Tue  |
+----+-------+----------------+
7 rows in set (0,00 sec)

mysql>