我怎么能将此列中的负值替换为0
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我怎么能将此列中的负值替换为0相关的知识,希望对你有一定的参考价值。
SUM([X Limited$Detailed Cust_ Ledg_ Entry].[Amount (LCY)]) AS DAmount
我怎么能在我试过的这一列中用0替换负值
select sUM(IF ([X Limited$Detailed Cust_ Ledg_ Entry].[Amount (LCY)] < 0, 0, X Limited$Detailed Cust_ Ledg_ Entry].[Amount (LCY)] )) as DAmount
答案
你可以使用案例
select sum(case when [X Limited$Detailed Cust_ Ledg_ Entry].[Amount (LCY)] >0
then [X Limited$Detailed Cust_ Ledg_ Entry].[Amount (LCY)] end ) as DAmount
另一答案
使用case
表达式:
(CASE WHEN SUM([X Limited$Detailed Cust_ Ledg_ Entry].[Amount (LCY)]) > 0
THEN SUM([X Limited$Detailed Cust_ Ledg_ Entry].[Amount (LCY)])
ELSE 0
END) AS DAmount
另一答案
用例何时
select case when SUM([X Limited$Detailed Cust_ Ledg_ Entry].[Amount (LCY)])<0 then 0 else SUM([X Limited$Detailed Cust_ Ledg_ Entry].[Amount (LCY)]) end
AS DAmount
另一答案
我注意到case语句有多个答案,但还有另一个选项可能会让你感兴趣(使用where子句)。
Select SUM([X Limited$Detailed Cust_ Ledg_ Entry].[Amount (LCY)]) AS DAmount
FROM Table
Where [X Limited$Detailed Cust_ Ledg_ Entry].[Amount (LCY)]>0
以上是关于我怎么能将此列中的负值替换为0的主要内容,如果未能解决你的问题,请参考以下文章