Here's an idea of what the temporary table contains:
| ID | FullRank | Special |
|---|---|---|
| 1 | 1 | No |
| 1 | 2 | Yes |
| 1 | 3 | No |
| 2 | 1 | Yes |
| 2 | 2 | No |
| 3 | 1 | No |
| 3 | 2 | Yes |
| 3 | 3 | Yes |
| 3 | 4 | No |
| 3 | 5 | No |
And this is what I'm trying to achieve...
| ID | FullRank | Special | SpecialRank |
|---|---|---|---|
| 1 | 1 | No | |
| 1 | 2 | Yes | 1 |
| 1 | 3 | No | 2 |
| 2 | 1 | Yes | 1 |
| 2 | 2 | No | 2 |
| 3 | 1 | No | |
| 3 | 2 | Yes | 1 |
| 3 | 3 | Yes | 2 |
| 3 | 4 | No | 3 |
| 3 | 5 | No | 4 |
Essentially, I want to insert another rank ('SpecialRank') that ranks from the first instance of 'Special' for an ID, based on the highest 'FullRank'.
I've tried variations of the following but without success:
UPDATE #SpecialTemp AS STa
INNER JOIN (SELECT MIN(STb.FullRank) STb.ID
FROM #SpecialTemp AS STb
GROUP BY STb.ID
) AS b
ON STa.ID = b.ID
AND STa = 'Yes'
SET STa.SpecialRank = 'Yes'
I'm getting some syntax errors with this, and unsure if I'm taking the right approach with this. Thanks!
SpecialRank? Anyway, this might help to get you started: db<>fiddle