update a set a.col='C'
update a set a.col='B' where a.id in (select top 60 percents id from a order by col)
update a set a.col='A' where a.id in (select top 20 percents id from a order by col)这样算不算啊

解决方案 »

  1.   

    declare @i Numeric(28.6),@RCount Numeric(28.6)
    set @rcount=(select count(*) from 表)
    set @i=0
    if @rcount>0 
     update 表
       set
         字段=(case when @i/@rcount<1.000000/5 then 'A'
                    when @i/@rcount>=1.000000/5 and @i/@rcount<3.000000/5 then 'B'
                    else 'C'
                )
         ,@i=@i+1
      

  2.   

    to CrazyFor:
    你的方法应该是可行的,不过看起来还是有点儿不完善,
    是不是应该这样:
    declare @i Numeric(28,6),@RCount Numeric(28,6)
    set @rcount=(select count(首字段) from 表)
    set @i=0
    if @rcount>0 
    begin
    while @i<>(@rcount-1)
     begin
         update 表
            set
            字段=(case when @i/@rcount<1.000000/5 then 'A'
                    when @i/@rcount>=1.000000/5 and @i/@rcount<3.000000/5 then 'B'
                    else 'C'
                )
         ,
          @i=@i+1
       end
    end这样看起来可能更清楚一些,
    不过还有没有更好一点儿的方法,请大家指教
      

  3.   

    hanfey() ,不用套在循环中的,这样速度会慢很多!!
      

  4.   

    to CrazyFr:
    谢谢
    还是不死心,再求高解,要不然就结帖了
      

  5.   

    declare @i Numeric(28,6),@RCount Numeric(28,6)
    set @rcount=(select count(首字段) from 表)
    set @i=0
    if @rcount>0 
    begin
    while @i<(@rcount-1)-------------------------呵呵
     begin
         update 表
            set
            字段=(case when @i/@rcount<1.000000/5 then 'A'
                    when @i/@rcount>=1.000000/5 and @i/@rcount<3.000000/5 then 'B'
                    else 'C'
                )
         ,
          @i=@i+1
       end
    end
      

  6.   

    shb_zj() ,
    只要你套到一个循环中,速度就肯定没有我快了,一个语句和一个循环的区别相信不会很小.
    hanfey() ,
    是啊,做成一个存储过程,执行一下就可以了,还要高解你就出个100分,20分估计没人来跟我抢了.呵呵~~~~
      

  7.   

    shb_zj() ,
    只要你套到一个循环中,速度就肯定没有我快了,一个语句和一个循环的区别相信不会很小.
    hanfey() ,
    是啊,做成一个存储过程,执行一下就可以了,还要高解你就出个100分,20分估计没人来跟我抢了.呵呵~~~~
      

  8.   

    shb_zj() ,
    只要你套到一个循环中,速度就肯定没有我快了,一个语句和一个循环的区别相信不会很小.
    hanfey() ,
    是啊,做成一个存储过程,执行一下就可以了,还要高解你就出个100分,20分估计没人来跟我抢了.呵呵~~~~
      

  9.   

    CrayZyFor,thanks a million,hehe