派生列的配置单元查询

hive query for derived columns

能否请您指导。

输入 table (Table1) 有像 credit_date、credit_amount、debit_date、debit_amount、[=85= 这样的列], loan_amount.

输出 table(Table 2) 有像日期这样的列,credit_payment, Debit_payment, Loan_payment.

Date :应合并 credit_date、debit_date 和 loan_date.

的所有值

Credit_payment:求出给定 credit_date.

的积分总和

Debit_payment: 求给定 debit_date.

的借方金额总和

Loan_payment: 求给定 loan_date

的贷款总额

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

insert into table2 
select 
date,
debit_payment,
credit_payment,
Loan_payment
 from (
select 
sum(credit_amount) over parttion by credit_date as credit_payment,
sum(debit_amount) over parttion by debit_date as Debit_payment
sum(loan_amount) over parttion by loan_date as Loan_payment
from table1
union all
select credit_date as date from table1
union all
select debit_date as date from table1
union all
select payment_date as date from table1
) t

---------------------------------------- ------------------------------

我有另一种情况,其中 credit_Date、debit_date 和 loan_date 可以相同。 输出 table 有以下列

日期: 应结合 credit_date、debit_date 和 loan_date ( credit_date、debit_date 和 loan_date 可以相同也可以不同)

**Credit_payment:**查找给定 credit_date、实体、货币、所有者

的信用额度总和

Debit_payment: 查找给定 debit_date、实体、货币、所有者

的借方金额总和

Loan_payment: 计算给定 loan_date、实体、货币、所有者

的贷款金额总和

实体: 来自 Table1

的值

货币: 值来自 Table 1

所有者: 值来自 Table 1

总计: (credit_payment + debit_payement+ loan_payment)

的总和

能否请您指导一下。

请找到如下截图。

您可能需要在执行 union all 之前明确指定空列:

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