一表ab,新建一字段,若前一字段数值大于5,则新字段数值为正,小于等于5为负?
id  数据1
1    4
2    6
3    8
4    1结果为
id  数据1  正负
1    4     负
2    6     正
3    8     正
4    1     负  
怎么写,谢谢!

解决方案 »

  1.   

    update ab
    set 正负=decode(数据1>5,'正','负') 
      

  2.   

    试了,不对啊,运行不了,decode是什么,提示找不到decode程序
      

  3.   


    --增加字段 使用语法
    --alter table 表名 add 列名 数据类型declare @t table (id int,数据1 numeric(9),正负 varchar(10))
    insert into @t(id,数据1) select 1,4
    insert into @t(id,数据1) select 2,6
    insert into @t(id,数据1) select 3,8
    insert into @t(id,数据1) select 4,1--select * from @t
    update @t set 正负=case when 数据1>5 then '正' else '负' end
    select * from @t
      

  4.   

    update ab 
    set 正负=iif(数据1>5,'正','负')