DECLARE @tbl TABLE ( EventId int, Section int, PlayerName...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Android Enthusiasts

Q&A for enthusiasts and power users of the Android operating system

DECLARE @tbl TABLE
(
EventId int,
Section int,
PlayerName nvarchar(100),
Score int,
Rank int
)

INSERT INTO @tbl VALUES(1, 1, 'Should be ', 31, -1)
INSERT INTO @tbl VALUES(1, 1, 'Should be ', 11, -1)
INSERT INTO @tbl VALUES(1, 1, 'Should be ', 1, -1)

UPDATE @tbl
SET Rank = t2.Rank
FROM @tbl t1
LEFT OUTER JOIN 
(
  SELECT EventId
  , Section
  , PlayerName
  , Score
  , RANK() OVER (ORDER BY Score desc) as Rank
  FROM @tbl
) as t2 
  ON t1.EventId = t2.EventId 
  AND t1.Section = t2.Section
  AND t1.PlayerName = t2.PlayerName

SELECT * from @tbl

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results