--創建測試環境
Create Table 表
(id Int,
c_id Int,
length Int,
flag_x Bit)
Insert 表 Select 1, 1212, 30, Null
Union All Select 2, 1212, 12, Null
Union All Select 3, 1212, 18, Null
Union All Select 4, 1212, 30, Null
Union All Select 5, 454, 32, Null
Union All Select 6, 454, 32, Null
Union All Select 7, 454, 87, Null
GO
--測試
Update A Set flag_x = 1 From 表 A Where id = (Select TOP 1 id From 表 Where c_id =A.c_id Order By length Desc, id)