declare @变量 intselect max(字段) from (select top n from 表 where ...)a

解决方案 »

  1.   

    --忘记给变量了
    declare @变量 intselect @变量=max(字段) from (select top n from 表 where ...)a
      

  2.   

    update 表 set 列名= XXX
    WHERE 字段=(select max(select top n from 表 where 列名=~~)from 表)
      

  3.   

    假定id是你表的主键
    exec('update b set b.fieldname='+@你的变量值
    +' from yourtable b,
    (
    select id,max(fieldname) fieldname 
    from (select top '+@n+' id,filedname from yourtable )a  group by id
    )a
    where a.id=b.id')