using pure sql, possibly but it would be very complicated. It is easy enough to find the previous record, but the problem you have is the rules for setting the grouping value.
You also need to be careful with your terminology. Databases do not have any concept of 'previous' unless an order is specified. Your data is conveniently in ascending order of ct1 and ct2 - but what if the 2nd and 3rd records are swapped?
I will assume 'previous' means when sorted by ct1 and ct2.
For these situations I use a function which can be used in a query. For your situation, it might look like this
Code:
Function CTGroup(Optional t As Variant = "", Optional v As Variant = -1) As Variant
Static X As Long
Static n
Static s
If v = -1 Then 'reset group on criteria
X = 0
n = 0
s = ""
ElseIf t < s Then 'reset group on refresh (selecting all to copy/paste for example)
X = 1
s = t
n = v
'elseif something - if user clicks on individual records, group value can change for example user clicks on 3rd record then the 2nd record
ElseIf t > s Or (t = s And v > n + 1) Then 'increment by one
X = X + 1
s = t
n = v
End If
CTGroup = X
End Function
edit: note the 'elseif something' comment. You have not said what you are going to do with the data, whether it needs to be editable, etc so you may need additional code to account for that situation.
Your query would be something like
Code:
SELECT Table1.ct1, Table1.ct2, ctgroup([ct1],[ct2]) AS ct3
FROM Table1
WHERE (((ctgroup())=False))
ORDER BY Table1.ct1, Table1.ct2;
which produces this result