如何计算购销数量之间的差异? [英] How to calculate the difference between purchase and sale quantity?
本文介绍了如何计算购销数量之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Ms Access数据库计算一次查询中的购买和销售数量之间的差异?
How can I calculate the difference between the purchase and sale quantity in one query using Ms Access database?
例如,我的数据如下:
ProductId Type Quantity
1 Purchase 24
1 Sale 1
我如何在一个查询中获得(24-1 = 23)的差异?
How would I get the difference of (24-1=23) in one query?
推荐答案
您可以自我加入表格:
SELECT p.productId, (p.quanity - COALESCE(s.quantity, 0)) difference
FROM table p
LEFT JOIN table s
ON p.type = 'Purchase' AND s.type = 'Sale' AND p.productId = s.productId
这篇关于如何计算购销数量之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文