ALTER TABLE "T_ONLINE_PAYMENT"
    ADD ("MAIN_ACCOUNT_MONEY" NUMBER(16,2))
ADD ("SUB_ACCOUNT_MONEY" NUMBER(16,2));

COMMENT ON COLUMN "CLOUD_2"."T_ONLINE_PAYMENT"."MAIN_ACCOUNT_MONEY" IS '分账-主账户金额';

COMMENT ON COLUMN "CLOUD_2"."T_ONLINE_PAYMENT"."SUB_ACCOUNT_MONEY" IS '分账-子账户金额'



-- 洗数据
MERGE INTO T_ONLINE_PAYMENT t
USING (
  SELECT
    tp.pk_id id,
    MAX(sad.TRADE_AMOUNT) maxMoney,
    MIN(sad.TRADE_AMOUNT) minMoney
  FROM
    T_ONLINE_PAYMENT_SEP_ACC_D sad
    LEFT JOIN T_ONLINE_PAYMENT_SEP_ACC sa ON sa.PK_ID = sad.PK_SEP_ACC
    LEFT JOIN T_ONLINE_PAYMENT tp ON tp.pk_id = sa.PK_PAYMENT
  GROUP BY
    tp.pk_id,
    sad.pk_sep_acc
) result
ON (t.pk_id = result.id)
WHEN MATCHED THEN
UPDATE SET
    t.MAIN_ACCOUNT_MONEY = result.maxMoney,
    t.SUB_ACCOUNT_MONEY = result.minMoney;
