简体   繁体   English

忽略减去语句中的列

[英]ignore column in minus statement

I am unable to find a solution to this problem. 我无法找到解决此问题的方法。

There are two tables to minus from each other. 有两个表相互减去。

Select columnA, columnB, columnC from tableA
minus
Select columnA, columnB, columnC from tableB

I need the data from tableA.columnC, however it will never match to tableB.columnC, so the minus statement will return both records. 我需要来自tableA.columnC的数据,但它永远不会与tableB.columnC匹配,因此minus语句将返回两个记录。

Is there a way to ignore columnC from the minus statement but still return the results? 有没有办法从minus语句中忽略columnC但仍返回结果?

-Thanks -谢谢

PS A little background on this problem. PS关于这个问题的一点背景。 I have a transaction table that list date of purchase, billed amount, item purchased (sometimes listed, sometimes not), account number of purchaser, and a unique identifier for the purchase. 我有一个交易表,列出购买日期,开单金额,购买的项目(有时列出,有时没有),购买者的帐号,以及购买的唯一标识符。

This table holds both purchases and reversals. 此表包含购买和撤消。 So if someone bought a item for 10.00 and then returns the item there is a -10.00 for that. 因此,如果有人为10.00购买了一件物品,然后返回该物品则为-10.00。 In some cases a person will buy, return, and buy that item again within the same day. 在某些情况下,某人会在同一天内再次购买,退货和购买该商品。 This data is from a third party. 此数据来自第三方。

Unfortunately a sum does not work in this case I need a line by line detail of all purchases that have not been reversed. 不幸的是,在这种情况下,总和不起作用我需要一行一行的详细信息,所有购买都没有被撤消。

I was able to get the correct data by following this posts advice and using a: Prevent Oracle minus statement from removing duplicates 通过遵循这些帖子建议并使用: 防止Oracle减去语句删除重复项,我能够获得正确的数据

However there is more information that I need from this table than just the information that I am using to minus off the returns. 但是,我需要从这个表中获得更多信息,而不仅仅是我用来减去回报的信息。

This is why i would like help with the above statement. 这就是为什么我想要帮助上述声明。

something on these lines should work: 这些行上的东西应该有效:

Select columnA, columnB, columnC from tableA a
where not exists
(Select 1 from tableB b where a.columnA=b.columnA and a.columnB=b.columnB)

Try this: 尝试这个:

select cola,colb,colc from tableA as A
inner join
(select cola,colb from tableA
 minus
 select cola,colb from tableB) as B
 on a.cola = b.cola
 and a.colb = b.colb;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM