0

我需要选择从今天开始的 40 行和 10 条日期较旧的记录,按日期排序。

如果 MySQL 支持负偏移量,它看起来像这样:

SELECT * FROM `mytable` WHERE `date` >= '2013-10-29' ORDER BY date LIMIT -10, 40;

不支持负偏移。我该如何解决这个问题?谢谢!!!

4

1 回答 1

3

用于UNION组合两个查询:

(
  SELECT   *
  FROM     mytable
  WHERE    date < '2013-10-29'
  ORDER BY date DESC
  LIMIT    10
) UNION ALL (
  SELECT   *
  FROM     mytable
  WHERE    date >= '2013-10-29'
  ORDER BY date
  LIMIT    40
)
ORDER BY date -- if results need to be sorted
于 2013-10-29T19:00:44.070 回答