我在提取财务信息,但却遇到了反收费信息。基本上,如果有人因为一项服务而被收费,那么就会有一个带有这项费用的专栏。如果电荷后来反转,则会有另一行具有完全相同的数据,但上面有电荷反转标志。我只想得到没有被撤销的指控。下面是我的意思和需要的例子。如您所见,如果电荷是反转的,RVSLInd列有1。0表示初始电荷。
我做不到:从rvslInd = 0的表中选择*。因为这只会去掉倒转行。
RvslInd|ExtPriceAmt
-------| ----------|
0 | 155.70 |
0 | 1.50 |
0 | 239.00 |
0 | 1111.00 |
1 | -1111.00 |
0 | 217.00 |
0 | 1491.00 |
1 | -1491.00 |
0 | 388.00 |
0 | 72.00 |这就是我想要得到的:
RvslInd|ExtPriceAmt
-------| ----------|
0 | 155.70 |
0 | 1.50 |
0 | 239.00 |
0 | 217.00 |
0 | 388.00 |
0 | 72.00 |这将是我的新表,并添加了一个customer列:
CustomerID|RvslInd|ExtPriceAmt
----------|-------| ----------|
1 | 0 | 155.70 |
1 | 0 | 1.50 |
1 | 0 | 239.00 |
2 | 0 | 217.00 |
2 | 0 | 388.00 |
2 | 0 | 72.00 |发布于 2017-09-14 20:46:35
根据您的数据,您无法可靠地做您想做的事情。对于您显示的数据,您可以:
select ExtPriceAmt
from t
where RvslInd = 0 and
not exists (select 1 from t t2 where t2.ExtPriceAmt = - t.ExtPriceAmt and t2.RvslInd = 1);问题是当价格被重复的时候。那就挡道了。
话虽如此,并非一切都是无望的。您可以获得价格列表以及不可反转次数:
select ExtPriceAmt,
sum(case when RvslInd = 0 then 1 when RvslInd = 1 then -1 end) as non_reversed_count
from t
group by ExtPriceAmt
having sum(case when RvslInd = 0 then 1 when RvslInd = 1 then -1 end) > 0;https://stackoverflow.com/questions/46227937
复制相似问题