按升序选择最新结果

时间:2011-09-25 08:16:44

标签: mysql

我目前正在使用mysql查询: SELECT COUNT(*), time FROM visit GROUP BY time ORDER BY time DESC LIMIT 14 从mysql数据库中获取最近的14个“COUNT(*)”。不幸的是,它们处于倒退状态。

如果我将DESC替换为ASC它们的顺序正确,但我得到的是14个最旧的而不是最新的14个。我怎样才能以正确的顺序获得这些?任何帮助赞赏。谢谢:))

2 个答案:

答案 0 :(得分:5)

您必须添加别名

select * from 
    (select count(*), time from visit group by time order by time desc limit 14) as t
order by time 

答案 1 :(得分:3)

您可以将其包装在另一个选择中:

SELECT * FROM 
    (SELECT COUNT(*), time FROM visit GROUP BY time ORDER BY time DESC LIMIT 14) as SUB
ORDER BY time ASC