Table: MyData
============================
id | Name | Surname
----------------------------
1 | AB | ABAB
2 | CD | CDCD
3 | EF | EFEF
4 | CD | CDCD
5 | CD | CDCD
6 | AB | ABAB
7 | CD | CDCD
8 | CD | CDCD
Selezionare il id
per il record per un nome specifico per il conteggio dato così vale a dire: In primo luogo ho i nomi distinti
AB
CD
EF
Poi desidero ottenere il ID
per il 3 occorrenza di ciascun account in modo che iniziano con AB
For name AB
Start with id = 1
eg: SELECT id FROM MyData WHERE id >= 1 Name = 'AB' and count <= 3 --Should return id=6 as there are only 2 occurrences so it should just return the last one
For name CD
Start with id = 1
eg: SELECT id FROM MyData WHERE id >= 1 Name = 'CD' and count <= 3 --Should return id=5 as record 5 contains the 3 occurrence
Set id = returned id + 1 so start id = 6
eg: SELECT id FROM MyData WHERE id >= 6 Name = 'CD' and count <= 3 --Should return id=8 as from id 6 the last occurrence is at id 8
For name EF
Start with id = 1
eg: SELECT id FROM MyData WHERE id >= 1 Name = 'EF' and count <= 3 --Should return id=3
Sto lottando per trovare un modo pulito per ottenere questo risultato con MS SQL. Qualsiasi aiuto apprezzato