更新时间:2023-02-11 09:33:31
用CASE表达式替换ifs:
Replace ifs with CASE expressions:
if (latitudinalDifference == 0)
{
if (longitudinalDifference != 0)
{
azimuth = Math.PI / 2d;
}
}
替换为:
SELECT CASE WHEN @latitudinalDifference = 0 AND @longitudinalDifference <> 0 THEN ...
ELSE ... END AS azimuth
使用嵌套选择替换连续ifs:
replace consecutive ifs with nested selects:
if(some condition)
{
i=1;
}
else
{
i=2;
}
if(some other condition)
{
i++;
}
替换为
SELECT i + CASE WHEN (some other condition) THEN 1 ELSE 0 END
FROM(
SELECT CASE WHEN (some condition) THEN 1 ELSE 2 END AS i
) AS t