将表1的总数量减去表2

时间:2015-05-25 14:20:59

标签: sql netbeans derby javadb

伙计我在按DeliveriesReturns分组的TOTAL_QUANTITY减去两个表(CONTAINER_TYPECUSTOMER_NAME)时遇到此问题如果我减去例如Customer_Balance,则示例查询会返回0的{​​{1}}列,但如果我减去5 - 0,则会返回5 -1

4
你可以告诉我我做错了什么吗?谢谢!

1 个答案:

答案 0 :(得分:0)

(TOTAL_DELIVERY.TOTAL_QUANTITY - TOTAL_PULLOUT.TOTAL_QUANTITY)

必须是

(coalesce(TOTAL_DELIVERY.TOTAL_QUANTITY,0) - coalesce(TOTAL_PULLOUT.TOTAL_QUANTITY, 0))