上位の値を事前に計算し、UPDATE を実行する前に一時テーブルに保存します:
SELECT
R1.Date,
R1.ContestID,
(SELECT TOP 1 R2.Position
FROM Results R2
WHERE R2.Date = R1.Date AND R2.ContestID = R1.ContestID
ORDER BY R2.Position DESC) AS TopPosition
INTO #temp
FROM
(SELECT DISTINCT Date, ContestID FROM Results) R1;
UPDATE Results R
SET R.Points = 100 + ((100/((SELECT TopPosition FROM #temp T
WHERE T.Date = R.Date AND
T.ContestID = R.ContestID)-4) *
((SELECT TopPosition FROM #temp T
WHERE T.Date = R.Date AND
T.ContestID = R.ContestID)-R.Position)))
WHERE R.ContestID > 11
AND R.Position > 4
AND R.Position < (SELECT TopPosition FROM #temp T
WHERE T.Date = R.Date AND T.ContestID = R.ContestID);
ただし、NumberOfResults
がどうなるかはわかりません および NumberOfPlaces
が定義されています。トップ ポジションを選択していますが、数値を計算していません。これを SELECT に追加できます:
...,
(SELECT COUNT(*)
FROM Results R2
WHERE R2.Date = R1.Date AND R2.ContestID = R1.ContestID) AS NumberOfResults
INTO ...