我有一张桌子t_status
form_no | status | date_added
1 | ok | 2013-06-01 15:03:07
2 | ok | 2013-05-29 10:13:27
3 | ng | 2013-05-30 11:09:47
4 | ng | 2013-06-03 08:13:17
date_added的类型是:datetime。
现在,当我使用ORDER BY date_added DESC
排序时,它将是这样的:
3 | ng | 2013-05-30 11:09:47
2 | ok | 2013-05-29 10:13:27
1 | ok | 2013-06-01 15:03:07
4 | ng | 2013-06-03 08:13:17
我的问题是,如何按date_added排序,以便输出可以像这样(从最近的日期到最早的日期):
4 | ng | 2013-06-03 08:13:17
1 | ok | 2013-06-01 15:03:07
3 | ng | 2013-05-30 11:09:47
2 | ok | 2013-05-29 10:13:27
答案 0 :(得分:2)
此查询绝对适用于您:
SELECT *
FROM t_status
ORDER BY date_added DESC
考虑到你有一个类似于这样的表:
CREATE TABLE `t_status` (
`form_no` int(11) NOT NULL AUTO_INCREMENT,
`status` varchar(2) DEFAULT NULL,
`date_added` datetime DEFAULT NULL,
PRIMARY KEY (`form_no`)
) ENGINE=InnoDB AUTO_INCREMENT=5;