CREATE TABLE tabTest(UserId int, DefinitionId int,ConditionId int)
insert into tabTest VALUES(1, 1, 2), (2, 1, 2 ), (3, 1, 2 ), (4, 1, 2 ), (5, 2, 2 ), (6, 2, 2 )
;with cte
as (
SELECT *, row_number() OVER(ORDER BY UserId) rn, COUNT(*) over() cnt
FROM tabTest
)
UPDATE t
SET t.conditionId = CASE WHEN rn <= cnt/2 THEN 1 ELSE 2 END
FROM tabTest t JOIN cte c ON t.UserId = c.UserId
SELECT * FROM tabTest
Note: Here UserId is Unique
--
Chandu