问题
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