我想编写一个 MERGE 语句,通过使用 ORDER BY 子句从大表中选择前 10 行并将其更新为列值之一。MERGE 语句允许我选择 TOP 10 行,但我无法将 ORDER BY 子句放在任何地方。
MERGE TOP(10) StudentAllocation AS SA
USING (SELECT @sub_id AS subId) AS TSA ON SA.sub_id = TSA.subId
WHEN MATCHED THEN
UPDATE SET SA.exam_batch = 1);