我有一个名为rev的impala表,它有电汇代码、金额和每个电汇代码的报告行。
+---------+------+----------------+
|wire_code| amt | Reporting_line |
+---------+------+----------------+
| abc | 100 | Database |
+---------+------+----------------+
| abc | 10 | Revenue |
+---------+------+----------------+
| def | 50 | Database |
+---------+------+----------------+
| def | 25 | Polland |
+---------+------+----------------+
| ghi | 250 | Cost |
+---------+------+----------------+
| jkl | 300 | Cost |
+---------+------+----------------+
and the other table is FA which is having wire_code and Ajusted_wire_code
+---------+------+
|wire_code|adj_wc|
+---------+------+
| abc | def |
+---------+------+
| ghi | jkl |
+---------+------+
I need to adjust the amount of wire code which is available as adj_wc in FA table.
For example:
“”在fa表格中,它被调整为“def”,那么我的输出应该是-电线代码“def”的金额(和def)如下,“”金额将保持不变。
我正在使用下面提供的查询,它正在删除两个wire代码中不常见的记录,例如,def with reporting line,polland。有一个额外的报告行收入,需要添加到def代码中,因为正在转移到def。
正在调整到def-中没有的def报告行将保持不变,并调整通用报告行。
select r.wire_code, r.amt+coalesce(a.amt,0) as amt
from REV r
left outer join FA f on r.wire_code=f.adj_wc --adjustments
left outer join REV a on f.wire_code=a.wire_code --adjusted amount
Where REP.REPORTING_LINE = REP1.REPORTING_LINE
;
预期结果:
+---------+------+----------------+
|wire_code| amt | Reporting_line |
+---------+------+----------------+
| abc | 100 | Database |
+---------+------+----------------+
| abc | 10 | Revenue |
+---------+------+----------------+
| def | 150 | Database |
+---------+------+----------------+
| def | 10 | Revenue |
+---------+------+----------------+
| def | 25 | Polland |
+---------+------+----------------+
| ghi | 250 | Cost |
+---------+------+----------------+
| jkl | 550 | Cost |
+---------+------+----------------+
1条答案
按热度按时间qc6wkl3g1#
我想在Hive里工作
试试 Impala ,让我知道