本文介绍了Access SQL如何在SELECT查询中增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL查询给我X个结果,我希望查询输出有一个称为算是让查询变得像这样:

I Have an SQL query giving me X results, I want the query output to have a coulmn calledcount making the query somthing like this:

count id section
1     15    7
2     3     2
3     54    1
4     7     4

我该如何做到这一点?

How can I make this happen?

推荐答案

好的,我想这已经足够构成答案了:以下链接指定了两种方法: http://www.techrepublic.com/blog/microsoft-office/an-access -query-returning-nth-record/

Alright, I guess this comes close enough to constitute an answer: the following link specifies two approaches: http://www.techrepublic.com/blog/microsoft-office/an-access-query-that-returns-every-nth-record/

第一种方法假定您具有ID值并使用DCount(类似于@mikeY的解决方案).

The first approach assumes that you have an ID value and uses DCount (similar to @mikeY's solution).

第二种方法假设您可以创建一个VBA函数,该函数将对记录集中的EACH记录运行一次,并且每次需要运行计数时都需要手动重置(使用某些VBA)-因为它使用一个静态"值来运行其计数器.

The second approach assumes you're OK creating a VBA function that will run once for EACH record in the recordset, and will need to be manually reset (with some VBA) every time you want to run the count - because it uses a "static" value to run its counter.

只要您拥有合理的数字(数百个,而不是数千个)或记录,第二种方法对我来说似乎是最简单/最有效的.

As long as you have reasonable numbers (hundreds, not thousands) or records, the second approach looks like the easiest/most powerful to me.

这篇关于Access SQL如何在SELECT查询中增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 21:00