如何使用别名或变量比较SQL中的值
我正在将SQLs别名设置为变量,以替换下面的excel公式如何使用别名或变量比较SQL中的值,sql,ingres,Sql,Ingres,我正在将SQLs别名设置为变量,以替换下面的excel公式 =+IF((O2+Z2)=0,0,+IF(AA2=0,(O2*-1),+IF(AND(AA2>0,(((R2*O2)/(O2+Z2))+H2)<= (O2*-1)),(O2*-1),(((R2*O2)/(O2+Z2))+H2)))) 使用CASE语句,如: CASE WHEN Balance = 0 THEN -- some value, or a formula WHEN Balance < 0 THEN
=+IF((O2+Z2)=0,0,+IF(AA2=0,(O2*-1),+IF(AND(AA2>0,(((R2*O2)/(O2+Z2))+H2)<= (O2*-1)),(O2*-1),(((R2*O2)/(O2+Z2))+H2))))
使用
CASE
语句,如:
CASE
WHEN Balance = 0 THEN -- some value, or a formula
WHEN Balance < 0 THEN -- maybe some other value, or a formula
ELSE -- another value, or formula
END AS Something
安格尔。这是由一家名为ACTIAN Software的公司提供的
CASE
WHEN Balance = 0 THEN -- some value, or a formula
WHEN Balance < 0 THEN -- maybe some other value, or a formula
ELSE -- another value, or formula
END AS Something
SELECT CASE
WHEN Balance = 0 THEN 0
ELSE Something / Balance
END AS SomethingDividedByBalance
FROM (SELECT -- huge formula ending with AS Balance
, -- another formula AS Something
FROM yourTables
) subquery