访问 SQL 如何在 SELECT 查询中进行增量 [英] Access SQL how to make an increment in SELECT query

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

问题描述

我有一个 SQL 查询给我 X 个结果,我希望查询输出有一个名为计数使查询像这样:

I Have an SQL query giving me X results, I want the query output to have a coulmn called count 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-that-returns-every-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 函数,该函数将为记录集中的每个记录运行一次,并且每次要运行计数时都需要手动重置(使用某些 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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆