首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

select潜套有关问题

2012-01-22 
select潜套问题updatetestsettemp 1wherenewid(selecttop40*fromtestorderbynewid())当然,上面的语句是

select潜套问题
update   test   set   temp= '1 '   where   newid=(select   top   40   *   from   test   order   by   newid())  

当然,上面的语句是错误的,把随机查询到的记录,把temp字段设置成1
请问如何写才正确?

[解决办法]
newid是你表的字段?

如果不是,不能这么用。

假设你表中的字段中有唯一字段ID,则:

update test set temp= '1 '
where ID in (select top 40 ID from test order by newid())

热点排行