从两个表中减去值并返回所有字段的值,如果表2中没有值返回第一个表的值 [英] Subtract values from two tables and returns values for all fields and if no values in table 2 return the value of the first table
本文介绍了从两个表中减去值并返回所有字段的值,如果表2中没有值返回第一个表的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
选择 SUM(item_store.quantity) - (选择 SUM (transaction_items_store.quantity) AS exp2 来自 transaction_items_store
其中 transaction_items_store.item_no = item_store.item_no) as Q
FROM item_store
group by item_store.item_no
===========输出======= >
4
10
7
NULL
NULL
解决方案
这听起来像你真正的问题是如何选择空值为零 [ ^ ]?
实际语法取决于您使用的实际数据库。 此谷歌搜索结果 [ ^ ]为一些不同的数据库提供了几个选项。
希望这会有所帮助。
选择 SUM(item_store.quantity) -
(选择 IFNULL(SUM(transaction_items_store.quantity), 0 ) AS exp2 来自 transaction_items_store
其中 transaction_items_store.item_no = item_store.item_no) as Q
FROM item_store
group < span class =code-keyword> by item_store.item_no
select SUM(item_store.quantity) - (select SUM(transaction_items_store.quantity) AS exp2 from transaction_items_store
where transaction_items_store.item_no=item_store.item_no) as Q
FROM item_store
group by item_store.item_no
===========the output is =======
4
10
7
NULL
NULL
解决方案
It sounds like your real question is "How can I select a null value as a zero[^]?"
The actual syntax will depend on what actual database you are using. This google result[^] has a couple of options for some different databases.
Hope this helps.
select SUM(item_store.quantity) - (select IFNULL(SUM(transaction_items_store.quantity),0) AS exp2 from transaction_items_store where transaction_items_store.item_no=item_store.item_no) as Q FROM item_store group by item_store.item_no
这篇关于从两个表中减去值并返回所有字段的值,如果表2中没有值返回第一个表的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文