GREENPLUM的函數返回TABLE

返回Table類型:sql

CREATE OR REPLACE FUNCTION ads.fv_repay_detail() RETURNS
TABLE( product_id bigint, real_date character varying,
principal_tot NUMERIC, principal NUMERIC, interest NUMERIC) AS
$$ SELECT t3.product_id,
to_char(to_timestamp(t6.real_repay_date),
'yyyy-mm-dd') AS real_date,
(sum(CASE t6.real_repay_principal
WHEN -1 THEN
0
ELSE
((t6.real_repay_principal + t6.real_repay_interest) +
t6.real_repay_otherfee)
END) / 100) AS principal_tot,
(sum(CASE t6.real_repay_principal
WHEN -1 THEN
0
ELSE
t6.real_repay_principal
END) / 100) AS principal,
(sum(CASE t6.real_repay_interest
WHEN -1 THEN
0
ELSE
(t6.real_repay_interest + t6.real_repay_otherfee)
END) / 100) AS interest
FROM ods_asset.tb_repay_plan_detail t1
LEFT JOIN ods_asset.tb_loan t3
ON (t3.loan_id = t1.loan_id)
LEFT JOIN ods_asset.tb_repay_actual_detail t6
ON (t6.id = t1.actual_repay_associate_id)
WHERE t3.status not in (0, 1, 9 )
AND (t6.real_repay_date > 0)
GROUP BY to_char(to_timestamp((t6.real_repay_date) ),
'yyyy-mm-dd'),
t3.product_id
ORDER BY to_char(to_timestamp(t6.real_repay_date),
'yyyy-mm-dd')
$$ LANGUAGE sql;rest

相關文章
相關標籤/搜索