1

我想做的事情:

选择日期 = 2012-10-14 的行,然后显示该行之后的 4 行。所以从这个列表

2012-10-12 column #2
2012-10-13 column #2
2012-10-14 was very sunny.
2012-10-15 rained all day.
2012-10-16 whatever.
2012-10-17 column #2
2012-10-18 column #2
2012-10-19 rained all day.
2012-10-20 whatever.
2012-10-21 column #2
2012-10-22 column #2

它会返回这个:

2012-10-14 was very sunny.
2012-10-15 rained all day.
2012-10-16 whatever.
2012-10-17 column #2
2012-10-18 column #2

感谢帮助。

PS:数据库中没有周末的数据,所以有些日期会丢失。

4

2 回答 2

5
SELECT * FROM my_table WHERE date >= '2012-10-14' ORDER BY date LIMIT 5

sqlfiddle上查看。

于 2012-10-14T09:14:47.423 回答
1

此版本适用于日期范围,而不是固定数量的行。目前尚不完全清楚你想要哪一个。

select * from mytable where date_diff(date,'2012-10-14') <= 4 and date >= '2012-10-14';
于 2012-10-14T09:16:32.397 回答