我需要我购买的物品和我出售的物品之间的差异,我在这个表中购买的物品
ID |ItemName| PriceOfUnit | NumberOfItems I bought |DateIBought|
1 | tea | 3 | 6 |15/11/2015 |
2 | coffee | 5 | 4 |16/11/2015 |
3 | tea | 4 | 10 |20/12/2015 |
4 | juice | 5 | 15 | 1/1/2016 |
5 | coffee | 3 | 5 | 15/3/2016 |
6 | water | 5 | 2 | 16/4/2016 |
我卖的东西在这张表里
ID |ItemName| PriceOfUnit | NumberOfItems I sold |DateIBought|
1 | coffee | 5 | 6 | 1/1/2016 |
2 | tea | 5 | 9 | 15/3/2016 |
3 | coffee | 4 | 2 | 20/4/2016 |
4 | juice | 5 | 11 | 1/1/2016 |
我需要一个查询,SQL查询或联合查询在MS Access中得到这个结果?
ID |ItemName| NumberOfItems I have |
1 | coffee | 1 |
2 | tea | 7 |
3 | juice | 4 |
4 | water | 2 |
我怎样才能得到这个结果
其中NumberOfItems I have = NumberOfItems I bought - NumberOfItems I sold
您没有提供属性名或表名,而是指定了两个RDBMS产品,因此这里是您的解决方案的p代码:
问题1:SELECT ItemName,SUM(built)as SumBought from tBought GROUP BY ItemName
问题2:SELECT ItemName,SUM(已售出)作为SumSold从tSold GROUP BY ItemName
问题3:选择q1.ItemName,(SumBought-SumSold)作为与q1.ItemName=q2.ItemName 上的q1内部联接q2的差异