有一表:TableA
字段有:
---------------
AA   BB  CC 
1       
2    
3    
7
5
6
7
8
9
10
-------------------
现在做到以下的要求:
BB列的值为:AA列的值 除以 AA列的最大的5列的平均值
CC的值为:根据BB的值的大小自动增加排名,。           例如:AA列的最大5列的值的平均值为:(10+9+8+7+6)/5=8
                 那么BB,CC列的值为:
                AA   BB   CC
                1    1/8  10
                2    2/8  9
                3    3/8  8
                4    4/8  7
                5    5/8  6
                6    6/8  5
                7    7/8  4
                8    8/8  3
                9    9/8  2
                10   10/8 1不知道我说清楚了没有。呵呵。这样的问题在数据里面应该如何设置呢。只有50分了。谢谢大家!

解决方案 »

  1.   

    楼主的BB、CC动态值是随着着记录行变化的,建议BB、CC在想要时SQL语句生成
      

  2.   

    happyflystone(无枪的狙击手) ( ) 信誉:100   
       楼主的BB、CC动态值是随着着记录行变化的,建议BB、CC在想要时SQL语句生成
     
    --------------------------------------------------
    用存储过程可以实现吗?
      

  3.   

    用存储过程可以实现吗?----------------------
    当然可以呀,那样BB、CC的数据无法实时反应,你可在任务中调度,定时更新二列的值
      

  4.   


    select AA,
    [BB]=rtrim(AA)+'/'+(select rtrim(sum(AA)) from ta b where (select count(1) from ta where AA>=b.AA)=5),--显示1
    [BB1]=AA*1.0/(select rtrim(sum(AA)) from ta b where (select count(1) from ta where AA>=b.AA)=5),--显示2
    [CC]=(select count(*) from ta where AA>=a.AA)
    from ta a 
      

  5.   

    happyflystone(无枪的狙击手) ( ) 信誉:100    Blog   加为好友 roy_88(中国风_燃烧你的激情!!!) ( ) 信誉:100    Blog   加为好友 ===================================================================那CC列的排序问题,我如果用存储过程中,应该如何实现呢?
      

  6.   

    try :declare @t table(id int,pm int)insert @t select 90,0 union all
    select 91,0 union all
    select 93,0 union all
    select 30,0 union all
    select 33,0 union all
    select 88,0 union all
    select 98,0select * from @tselect id,(select count(1)+1 from @t where id > a.id) as pm
    from @t a/*
    id          pm          
    ----------- ----------- 
    90          0
    91          0
    93          0
    30          0
    33          0
    88          0
    98          0(所影响的行数为 7 行)id          pm          
    ----------- ----------- 
    90          4
    91          3
    93          2
    30          7
    33          6
    88          5
    98          1
    */