繁体   English   中英

如何选择SQL查询结果的特定部分?

[英]How to select a specific part of a SQL query result?

我有一个具有一百万行的MySQL表。 我的查询结果需要包含100行,并且必须按日期排序。

我现在想在查询中添加一个子句,例如,该子句可以告诉数据库“以ID为'5'的行之后的行开始结果”。 因此,我的结果将包含ID为4、3、2、6、8,...的行

亲爱的读者,您是可以让我摆脱困境的追寻数据库向导吗? ;)

查询:

SELECT id, type, content, date
FROM my_table
WHERE type = 'FI'
ORDER BY date ASC
LIMIT 100;

结果:

| id | type | content  | date       |
|----|------|----------|------------|
| 7  | FI   | ContentR | 2014-01-01 |
| 9  | FI   | ContentS | 2014-01-13 |
| 1  | FI   | ContentT | 2014-02-09 |
| 5  | FI   | ContentU | 2014-03-27 |
| 4  | FI   | ContentV | 2014-03-30 | ---|
| 3  | FI   | ContentW | 2014-04-01 |    |
| 2  | FI   | ContentX | 2014-06-10 |    |- The result I want
| 6  | FI   | ContentY | 2014-09-03 |    |
| 8  | FI   | ContentZ | 2014-12-09 |    |
 ...                                  ---|
SELECT id, type, content, date
FROM my_table
WHERE type = 'FI'
AND date > (SELECT date FROM my_table WHERE id = 5)
ORDER BY date ASC
LIMIT 100;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM