我有:
enum('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')<BR>
我希望能够从今天开始排序&#39;或日期(date_format(%a))
有没有办法解决枚举的索引和ROL的种类? (抱歉,那里有老派汇编语言) 或者,首先在PHP中更容易吗? 目前我只是有一个常规的
SORT BY students.day (the enum field)
答案 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>