Sql - 带 And 和 Or 的大小写表达式

Sql - Case expression with And, and Or

我可以用下面的公式做一些帮助。它目前有效,但我想向其中添加另一部分,但我不知道该怎么做

当前公式为:

,CASE
WHEN 
ABS(((t1.[RateAmount] - t1.[Amount]) / NULLIF (t1.[Amount],0) *100)) >1  
OR ABS(((t2.volume - t1.TotalVolume) / NULLIF (t1.TotalVolume, 0) *100)) >5 
THEN 1 ELSE 0 
END AS OverallThresholdDifference

但是我需要添加音量线,如果超过 5 且相差 2000 并且我的大脑一片空白

如有任何帮助,我们将不胜感激

干杯

 WHERE t2.volume > 5 AND OverallThresholdDifference > 2000

要在 where 子句中获取 OverallThresholdDifference,您需要派生整个查询。

时再添加一个
CASE
WHEN 
ABS(((t1.[RateAmount] - t1.[Amount]) / NULLIF (t1.[Amount],0) *100)) >1  
OR ABS(((t2.volume - t1.TotalVolume) / NULLIF (t1.TotalVolume, 0) *100)) >5 
THEN 1 
when
ABS(((t1.[RateAmount] - t1.[Amount]) / NULLIF (t1.[Amount],0) *100)) >5  
and ABS(((t2.volume - t1.TotalVolume) / NULLIF (t1.TotalVolume, 0) *100)) >2000 
THEN 2 

ELSE 0 
END AS OverallThresholdDifference