5

我有一张这样的桌子:

id  date_time
1   2/11/2013 7:05
2   2/11/2013 7:00
3   2/12/2013 7:00
4   2/14/2013 7:00
5   2/16/2013 7:00
6   2/17/2013 7:00
7   2/12/2013 7:05
8   2/14/2013 7:05
9   2/15/2013 7:05
10  2/16/2013 7:05
11  2/17/2013 7:05
12  2/13/2013 7:00
13  2/15/2013 7:00
14  2/13/2013 7:05

我需要它按 HOUR:MINUTE 排序,而不是按 DATE 排序,所以我在输出中得到这样的结果:

2/11/2013 7:00
2/12/2013 7:00
2/13/2013 7:00
2/14/2013 7:00
2/15/2013 7:00
2/16/2013 7:00
2/17/2013 7:00
2/11/2013 7:05
2/12/2013 7:05
2/13/2013 7:05
2/14/2013 7:05
2/15/2013 7:05
2/16/2013 7:05
2/17/2013 7:05

有没有办法直接用 MySQL 对输出进行排序?...我知道一旦我得到查询结果就可以通过 PHP 来做,但只是想知道 MySQL 是否可以做这样的事情?

我尝试了这样的查询:

SELECT * FROM my_table WHERE (date_time BETWEEN '$date_check_low' AND '$date_check_high') ORDER BY hour(date_time) ASC

但它会产生奇怪的结果......

4

2 回答 2

5
ORDER BY HOUR(date_time), MINUTE(date_time), date_time

或者

ORDER BY TIME(date_time), date_time
于 2013-02-10T11:42:16.897 回答
0

试试这个:

SELECT *
FROM my_table
WHERE (date_time BETWEEN '$date_check_low' AND '$date_check_high')
ORDER BY time(date_time),
         date_time;
于 2013-02-10T11:42:17.757 回答