我自己试着写的 update tablea set aid = bid from tableb where bid in (select top 200 bid from tableb) 结果:所有的tablea中的aid字段的值是 'AB300EF'{这是tableb中bid字段中的第一个记录的值},我错哪了呢?为什么不是一对一的呢?
;WITH Liang AS
(
SELECT *,rnk=ROW_NUMBER() OVER(ORDER BY GETDATE())
FROM tablea
)
UPDATE Liang SET aid=b.bid
FROM (
SELECT
*,rnk=ROW_NUMBER() OVER(ORDER BY GETDATE())
FROM tableB
) AS B
WHERE B.rnk BETWEEN 50 AND 250
AND Liang.rnk=B.rnk