SQL/银行/交易:收入超过一个月的客户

问题描述

嗨,我有一张“交易”表,其中包含来自不同客户的少量银行交易。在那个表中,我还有每笔交易的日期以及他们的月平均工资。此外,在不同的表“帐户”上,我可以随时获取这些客户中少数几个的银行帐户余额。

我现在有一个请求,要确定这些客户中哪些客户的收入超过一个月,并检查紧急储蓄/恢复能力。关于如何解决这个问题的任何想法?

表事务的 DDL:

CREATE TABLE transactions (
customer_id uuid NOT NULL,transaction_date varchar(10) NOT NULL,transaction_id varchar NOT NULL,transaction_amount numeric(10,2) NOT NULL,description varchar NULL,account_id uuid NOT NULL
)

表帐户的 DDL:

CREATE TABLE account(
    customer_id uuid NOT NULL,account_id uuid NOT NULL,provider_id int8 NOT NULL,account_sub_type varchar NOT NULL,current_balance numeric(10,2) NULL
)

到目前为止,我的 CTE/查询如下所示:

WITH
over_one_income AS (
SELECT  customer_id,"month","year",salary,transaction_amount,current_balance from 
    (
    SELECT ctf.customer_id,date_part('month',ctf.date_key::date) as "month",date_part('year',ctf.date_key::date) as "year",round(sum(ctf.amount)/24/30,2) as transaction_amount,round(sm.yearly_net/12) as salary,sum(caf.current_balance) as current_balance

    from transactions ctf 
    join account caf 
    on ctf.customer_id = caf.customer_id and ctf.account_id = caf.account_id 
    join customer cf
    on cf.customer_id = caf.customer_id 
    join  salary_gross_to_net  sm
    on cf.annual_gross_salary= sm.yearly_gross
    group by ctf.customer_id,ctf.date_key::date),sm.yearly_net
   ) epc
   )
   
   select *  from over_one_income

上面的查询输出如下:

enter image description here

解决方法

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

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

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