database 如何在 MS ACCESS 2007 查询中使用 LIMIT

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6107690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:12:05  来源:igfitidea点击:

how to use LIMIT in query of MS ACCESS 2007

databasems-accessselectlimit

提问by gautamlakum

I have created some queries in MS Access 2007. they are giving error if I use LIMITin query. Can anyone help me out in this? How to use LIMITin MS Access 2007 query?

我在 MS Access 2007 中创建了一些查询。如果我LIMIT在查询中使用它们,它们会给出错误。任何人都可以帮我解决这个问题吗?如何LIMIT在 MS Access 2007 查询中使用?

回答by Jacob

There is no LIMITkeyword in Access (if you use the JET engine). You can use TOP xto give the first x results. Usage:

LIMITAccess 中没有关键字(如果您使用 JET 引擎)。您可以使用TOP x来给出第一个 x 结果。用法:

SELECT TOP 5 id FROM users ORDER BY joindate

From Microsoft Jet Database Engine Programmer's Guide - Chapter 4:

来自Microsoft Jet 数据库引擎程序员指南 - 第 4 章

TOP N and TOP N PERCENT Predicates

Although you can use the WHERE and HAVING clauses to filter the selection of records, sometimes this isn't sufficient. For example, you may want to select all records where the state is CA, but only see the orders for the top 10 customers. Microsoft Jet provides TOP N and TOP N PERCENT predicates to limit the presentation of records after they're selected.

TOP N Predicate

You can use the TOP N predicate to specify that your query return only a specific number of records to your program:

TOP N 和 TOP N PERCENT 谓词

虽然您可以使用 WHERE 和 HAVING 子句来过滤记录的选择,但有时这还不够。例如,您可能希望选择状态为 CA 的所有记录,但仅查看前 10 位客户的订单。Microsoft Jet 提供 TOP N 和 TOP N PERCENT 谓词来限制记录被选中后的显示。

TOP N 谓词

您可以使用 TOP N 谓词来指定您的查询仅向您的程序返回特定数量的记录: