当前位置: 代码迷 >> Sql Server >> 以下功能不用 存储过程可以实现否?该怎么解决
  详细解决方案

以下功能不用 存储过程可以实现否?该怎么解决

热度:84   发布时间:2016-04-24 19:02:06.0
以下功能不用 存储过程可以实现否?
数据库中 有 A B C D E字段   。
a =b + c + d 
a   b  c  d                e
10   2  2 6
11  7   2  2
15   2  10  3
  现在想求出来b  c  d 中最大的结果值写到E 中  ,可以实现吗?
------解决方案--------------------

create table test (a int,b int ,c int,d int,e int)
insert into test values(10,2,2,6,null)
insert into test values(11,7,2,2,null)
insert into test values(15,2,10,3,null)

update test set e=case when b>=c and b>=d then b
when c>=b and c>=d then c
when d>=b and d>=c then d
end 
select * from test 
/*
10 2 2 6 6
11 7 2 2 7
15 2 10 3 10
*/
  相关解决方案