问题描述
我有两张桌子,一张是销售,一张是购买。在销售中,我只卖了一件商品。我买了那个项目两次。当我试图通过查询查看该项目的销售和购买时,该查询显示错误的结果。
我的查询是
I am having two tables one is sales and one is purchase. In sales I sold one item one time only. I purchased that item two times. When I tried to see that item sales and purchases with a query , that query showing wrong results.
my query is "
select salesDB.sales,purchDB.purchase from salesDB inner join purchDB on salesDB.id=purchDB.id where salesDB.id=1
结果如下所示
销售额购买
5000 10000
5000 15000
实际有一次只有我卖了。价值5000 / - 。我买了两次。价值25000
所以我错了。我创建了与salesDB.id(主键)和purchaseDB.id的关系
我尝试过的事情:
我搜索了解决方案,并从该网站找到了一些解决方案还有其他网站。我尝试过但结果相同。
results are like below
SALES PURCHASE
5000 10000
5000 15000
There actually one time only I sold. Value 5000/-. Two times I purchased. Value 25000
so where I did mistake. I created relation to salesDB.id(primary key) and purchaseDB.id
What I have tried:
I googled for solution and found some solutions from this site and other sites also. I tried those but same result.
推荐答案
select salesDB.id, 'SALE' as tranType, sales
from salesDB
UNION
select purchDB.id, 'PURC' as tranType, purchase
from purchDB
这应该给
1 SALE 5000
1 PURC 10000
1 PURC 15000
这篇关于MS-SQL给出了错误的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!