Sql server 条件数学方程
我需要在select查询期间执行一些求和,但是根据2个值,我需要执行不同的等式。希望有一个例子能说明这一点 基本上,我需要进行以下总结Sql server 条件数学方程,sql-server,tsql,sql-server-2000,Sql Server,Tsql,Sql Server 2000,我需要在select查询期间执行一些求和,但是根据2个值,我需要执行不同的等式。希望有一个例子能说明这一点 基本上,我需要进行以下总结 if x > y then (x - y + z) or if x < y then (x - x + z) basically i am setting this to 0. 到目前为止,我认为我可以使用两个表来转储x>y值和x
if x > y then (x - y + z) or
if x < y then (x - x + z) basically i am setting this to 0.
到目前为止,我认为我可以使用两个表来转储x>y值和x任何想法都可以使用case表达式
select case
when x > y then x - y + z
when x < y then x - x + z
else 0 -- x = y
end
from YourTable
可以使用大小写表达式
select case
when x > y then x - y + z
when x < y then x - x + z
else 0 -- x = y
end
from YourTable
看起来这里有3个值。。。你能详细说明一下你所需要的表格和结果吗?看起来你这里有3个值。。。你能详细说明你所需要的表格和结果吗?从技术上讲,这是一个case表达式,而不是case语句。@Damien_the_unsiver-当然可以。谢谢我在英语方面有点困难,但T-SQL几乎很流利:。从技术上讲,这是一个case表达式,而不是case语句。@Damien_,不信者-当然是。谢谢我在英语方面有点困难,但T-SQL几乎很流利:。