原始数据能不能给改造成:
id,no,val
0,0,10
0,1,20
0,2,20
0,3,20
0,4,30
1,0,100
1,1,200
2,2,300
^
改这里这样就可以用case when 

解决方案 »

  1.   

    update tableA set [percent]=cast(a.val as numeric(10,2)) /cast (b.val as numeric(10,2))
     from tableA a,(select val from tableA where id=1 and [no]=0) b where a.[id]=0
      

  2.   

    Update table set percent =val/100 where id=0 
    update table set percent =val/(select val from table where id=1 and no=2) where id=1 and (no=0 or no=1)
      

  3.   

    原始数据可以改:
    id,no,val
    0,0,10
    0,1,20
    0,2,20
    0,3,20
    0,4,30
    1,0,100
    1,1,200
    2,2,300CASE WHEN怎么用?
      

  4.   

    呵呵,改了就不用CASE WHEN了Update a1 
    set percent =convert(numeric(10,2),val)/(select sum(val) from a where id=a1.id)
    from a as a1
    where id<>2or(for query,这里用到用CASE WHEN):select *,(case when id=2 then 0 
         else convert(numeric(10,2),val)/(select sum(val) from a where id=a1.id) end) as percent
    from a as a1
      

  5.   

    不好意思,我是在ACCESS里用。好像不支持这种写法
      

  6.   

    access:select *,iif(id=2,0,val/(select sum(val) from a where id=a1.id)) as percent
    from a as a1
      

  7.   


    select id,no,val,iif(id=2,0,val/(select sum(val) from a where id=a1.id)) as percent
    from a as a1