在SQLite3中,是否可以列出特定行?
假设我有一个表格:
+--------------+--------------+------+-----+
| ID | Score | email | add |
+--------------+--------------+------+-----+
| 123 | 88 | [email protected] | somewhere |
| 456 | 77 | [email protected] | somewhere |
| 789 | 88 | [email protected] | somewhere |
| 111 | 77 |[email protected] | somewhere |
| 555 | 77 | [email protected] | somewhere |
|444 | 88 | [email protected] | somewhere
| 222 | 77 | [email protected] | somewhere |
| 333 | 88 |[email protected] | somewhere |
我的问题是可以选择 Score
列并仅打印前 3 个 88
和 77
分数吗?
我试过了,但似乎只给了我 3 88 分
SELECT Score
FROM Table_Name
WHERE Score = '88' OR Score = '77'
LIMIT 3
Let's say I have a table:
+--------------+--------------+------+-----+
| ID | Score | email | add |
+--------------+--------------+------+-----+
| 123 | 88 | [email protected] | somewhere |
| 456 | 77 | [email protected] | somewhere |
| 789 | 88 | [email protected] | somewhere |
| 111 | 77 |[email protected] | somewhere |
| 555 | 77 | [email protected] | somewhere |
|444 | 88 | [email protected] | somewhere
| 222 | 77 | [email protected] | somewhere |
| 333 | 88 |[email protected] | somewhere |
My question is it possible to select Score
column and ONLY print out first 3 88
and 77
Score?
I tried but it seems only give me 3 88 scores only
SELECT Score
FROM Table_Name
WHERE Score = '88' OR Score = '77'
LIMIT 3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先过滤表格,以便仅返回具有所需分数的行,然后使用
ROW_NUMBER()
窗口函数根据Score
对每个Score
的行进行排名>ID,以便您可以过滤掉超出每组前 3 行的行:对于 3.25.0 之前不支持窗口函数的 SQLite 版本,请使用相关子查询:
First filter the table so that only the rows with the scores that you want are returned and then use
ROW_NUMBER()
window function to rank the rows of eachScore
based onID
so that you can filter out the rows that exceed the first 3 of each group:For versions of SQLite prior to 3.25.0 that do not support window functions use a correlated subquery: