SQL问题急用

来源:百度知道 编辑:UC知道 时间:2024/05/02 09:56:21
update pubs.dbo.abc set re=x*y where op=’*’
update pubs.dbo.abc set re=x+y where op=’+’
update pubs.dbo.abc set re=x-y where op=’-’
update pubs.dbo.abc set re=x/y where op=’/’
如何把4句合成一句?

如果数据库是ORACLE和SQL SERVER,可以用下面的这个语句完成上述操作:

update pubs.dbo.abc
set re=
case op
when '*' then x*y
when '+' then x+y
when '-' then x-y
when '/' then x/y
else null
end