update table1 set name=case when a.yin>0 then 1 else a.yin 
where id=3  select sum(yin) as yin from table1 a where id=3

解决方案 »

  1.   

    我看是两句
    update table1 set name=case when a.yin>0 then 1 else a.yin 
    where id=3  select sum(yin) as yin from table1 a where id=3
      

  2.   

    update table1 
    set name=case when a.yin>0 then 1 else a.yin
    from  table1,(select sum(yin) as yin from table1 where id=3) as a
    where id=3
      

  3.   

    也可以这么写
    update table1 
    set name=case when sum(yin)>0 then 1 else sum(yin)
    where id=3
      

  4.   

    改一下就可以了
    update table1
    set name=case when (select sum(yin) from table1 a where id=table1.id)>0 then 1 
    else select sum(yin) from table1 a where id=table1.id) end
    where id=3