简体   繁体   English

SQL表LEFT OUTER联接查询

[英]SQL table LEFT OUTER join query

在此处输入图片说明

What's the solution for attached image? 附加图片有什么解决方案? How to remove null? 如何删除空值?

ClosingQty column should reflect the value purchase-sale, but its reflecting null value ClosingQty列应反映购买价值,但其反映为空值

The reason is that NULL is not the same as 0. Try this: 原因是NULL与0不同。请尝试以下操作:

P.Quantity-COALESCE(S.Quantity,0) AS ClosingQty

See here: http://www.w3schools.com/sql/sql_isnull.asp 看到这里: http : //www.w3schools.com/sql/sql_isnull.asp

Your solution is failing as S.QUANTITY is NULL, so any arithmetic on it will result in a NULL answer. 您的解决方案失败了,因为S.QUANTITY为NULL,因此对其进行任何算术运算都将导致NULL答案。 You will need to check for null, and replace with a valid number, for example 0. 您将需要检查是否为空,并替换为有效数字,例如0。

The following should work: 以下应该工作:

ISNULL(P.QUANTITY,0) - ISNULL(S.QUANTITY, 0) AS ClosingQty

The real question, though, is why is S.QUANTITY null in the first place? 但是,真正的问题是,为什么S.QUANTITY首先为null?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM