派生列的 Hive 查询并找到派生列的总数

问题描述

我有一个场景,credit_Date、debit_date 和loan_date 可以相同。输出表有以下列

日期:应该结合credit_date、debit_date和loan_date(credit_date、debit_date和loan_date可以相同(或)为空)

Credit_payment:查找给定信用日期、实体、货币、所有者的信用金额总和

Debit_payment:查找给定借记日期、实体、货币、所有者的借记金额总和

Loan_payment:查找给定贷款日期、实体、货币、所有者的贷款金额总和,

实体:来自表 1 的值

货币:表 1 中的值

所有者:表 1 中的值

总计:(credit_payment + debit_payement+loan_payment)的总和

我试过下面的查询但没有用

insert into table2 
select *
from (
    select credit_date as date,sum(credit_amount) as credit_payment,null as debit_payment,null as loan_payment,entity,owner,currency
    from table1
    group by credit_date,currency
    union all
    select debit_date as date,null as credit_payment,sum(debit_amount) as debit_payment,currency
    from table1
    group by debit_date,currency 
    union all
    select loan_date as date,sum(loan_amount) as loan_payment,currency
    from table1
    group by loan_date,currency
) t
order by date;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)