MS Access Restart Number Sequence

你。 提交于 2021-02-04 06:51:33

问题


trying to do a sequence count in MS Access where the count sequence resets based on another field, so example below, trying to figure out ColB:

ColA ColB
4566 1
5677 1
5677 2
5677 3
8766 1
8766 2
1223 1

Think it might have something to do with the DCount() function, unsure. Would very much appreciate the help ... Thanks!


回答1:


Calculating a group sequence number in Access query is fairly common topic. Requires a unique identifier field, autonumber should serve.

Using DCount():

SELECT *, DCount("*", "table", "ColA=" & [ColA] & " AND ID<" & ID) + 1 AS GrpSeq FROM table;

Or with correlated subquery:

SELECT *, (SELECT Count(*) FROM table AS D WHERE ColA=table.ColA AND ID<table.ID)+1 AS GrpSeq FROM table;

An alternative to calculating in query is to use RunningSum property of textbox on a Report with Sorting & Grouping settings.



来源:https://stackoverflow.com/questions/64565228/ms-access-restart-number-sequence

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!