SQL Server的条件判断
比如我现在有一个列C,他存储的是一个天数,我现在有一个列D存储过去罚款,我需要列D的数据为(C-30)*0.8,如果C小于30则为0,select *,(case when c>=30 then (C-30)*0.8 else 0 end) as E into table_name_bak from table_name
上面的语句table_name为你的表名,功能是能够新建个table_name_bak 的表 这个表新曾了列E ,列E 的数据为 (C-30)*0.8 ,如果C小于30则为0
----------------
一般不建议更改基本表,但可以建个视图,例如:
create view view_表名
as select C ,(case when c>=30 then (C-30)*0.8 else 0 end) as D from 表名将表名改成你的基础表名,就是可以使用了!
--------------------------------------------------------------------------------
select (case when c>=30 then (C-30)*0.8 else 0 end) as d from table_name
页:
[1]