0

I have a table in Access like this:

ID |  Op_ID  
1  |  1  
1  |  2  
2  |  3  
3  |  4  
3  |  5  
3  |  6  

Is there a SELECT query that I can run in Access that would give me something like this?:

ID |  Count(ID)  
1  |  1  
1  |  2  
2  |  1  
3  |  1  
3  |  2  
3  |  3 

So basically I want a Count of ID that loops over ID every time ID changes.

3

This query simulates a RANK() function.

SELECT T1.ID, (SELECT COUNT(*) 
               FROM YOUR_TABLE T2 
               WHERE T1.ID = T2.ID AND T1.OP_ID >= T2.OP_ID) AS Rank 
FROM YOUR_TABLE T1
ORDER BY ID, OP_ID

It works only if there is an unique ID field that allow to count records where:

T1.OP_ID >= T2.OP_ID

enter image description here

  • Just what i needed! – SQLserving May 30 '17 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.