查询:
select id , 数A , 数B , 法则 ,
case
when 法则=1 then 结果=(数A+数B)/4
when 法则=2 then 结果=(数A-数B)/4
when 法则=3 then 结果=数A*数B/4
when 法则=4 then 结果=数A/数B/4
end as 结果
from 表
select id , 数A , 数B , 法则 ,
case
when 法则=1 then 结果=(数A+数B)/4
when 法则=2 then 结果=(数A-数B)/4
when 法则=3 then 结果=数A*数B/4
when 法则=4 then 结果=数A/数B/4
end as 结果
from 表
update 表 set 结果=a.结果 from
(
select id , 数A , 数B , 法则 ,
case
when 法则=1 then 结果=(数A+数B)/4
when 法则=2 then 结果=(数A-数B)/4
when 法则=3 then 结果=数A*数B/4
when 法则=4 then 结果=数A/数B/4
end as 结果
from 表
) a where 表.id=a.id
1.查询
select id,数A,数B,法则,
case
when 法则=1 then (数A+数B)/4
when 法则=2 then (数A-数B)/4
when 法则=3 then 数A*数B/4
when 法则=4 then 数A/数B/4
end as 结果
from 表2.修改
update 表set 结果=a.结果 from
(
select id,数A,数B,法则,
case
when 法则=1 then (数A+数B)/4
when 法则=2 then (数A-数B)/4
when 法则=3 then 数A*数B/4
when 法则=4 then 数A/数B/4
end as 结果
from 表
) a where 表.id=a.id
case
when 法则=1 then (数A+数B)/4
when 法则=2 then (数A-数B)/4
when 法则=3 then 数A*数B/4
when 法则=4 then 数A/数B/4
end我觉得这样就可以了
case
when 法则=1 then (数A+数B)/4then后面还可以嵌入case吗?
declare @i int
declare @j int
set @i=33
set @j=23
select case when @i>@j then @i else
case when @j>@i then @j end
end