需要根据日期拉最后x行数 [英] Need to pull last x number of rows based on date
本文介绍了需要根据日期拉最后x行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张表格,其中的日期为"2009年8月23日"格式,并且有5个值,因此看起来像这样
I have a table with dates in "Aug 23, 2009" format and 5 values, so that it looks like this
SELECT * FROM table;
Date | Total | V1 | V2 | V3 | V4
Aug 21, 2009 | 41 | 23 | 8 | 8 | 2
Aug 22, 2009 | 39 | 22 | 8 | 7 | 2
Aug 23, 2009 | 35 | 20 | 6 | 7 | 2
Aug 24, 2009 | 34 | 20 | 6 | 6 | 2
Aug 25, 2009 | 32 | 19 | 5 | 6 | 2
Aug 26, 2009 | 31 | 19 | 5 | 5 | 2
Aug 27, 2009 | 30 | 19 | 5 | 5 | 1
所以我需要一个查询,该查询将只给我最新的(底部)3个条目.我应该按日期设置一些查询还是只对最后3行设置一个限制?我尝试执行一个具有限制的子查询,但是我的MySQL版本不支持子查询中的LIMIT,据我所知,没有办法对负的最后一行数进行负限制.
So I need a query that will give me only the most recent (bottom) 3 entries. Should I setup some query by the date or just set a limit to the last 3 rows? I tried doing a subquery with a limit, but my version of MySQL does not support LIMIT in subquery, and to my knowledge there is no way to do a negative limit to grab the last x number of rows.
推荐答案
select *
from table
order by Date desc
limit 0, 3
这篇关于需要根据日期拉最后x行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文