用这个语句修改前3个qu字段的值 update tab set qu=1 Where id in (select top 3 id From tab ORder BY [score] asc)

解决方案 »

  1.   

    select  avg(a.分數)  from table    a  left  join 
     (select top 5  * from  table   order by  分數) b  on a.關鍵字=b.關鍵字  left  join     (  select top 5  * from table   order by  分數 desc ) c on a.關鍵字=c.關鍵字
    where a.分數<>b.分數 or a.分數<>c.分數 or b.關鍵字 is null or c.關鍵字 is null
      

  2.   

    --如果表中有主键,(如果没有,可以增加一个标识字段),可以直接这样计算平均
    --假设主键名为idselect avg(分数) from 表
    where id not in(
        select top 5 id from 表 order by 分数      --去掉5个最低分
        union all
        select top 5 id from 表 order by 分数 desc --去掉5个最高分
    )
      

  3.   

    更新前5条
    Update 表 Set 字段=1 Where ID IN (Select Top 5 ID from 表 order By 分数)更新后5条
    Update 表 Set 字段=1 Where ID IN (Select Top 5 ID from 表 order By 分数 Desc)
      

  4.   

    一句就行了:select 人名,avg(分) from (
    select 人名,分 from tb a where (select count(*) from tb where 分数>a.分数)>5 
    union
    select 人名,分 from tb a where (select count(*) from tb where 分数<a.分数)>5 
    ) a group by 人名