SQL练习—4

来源:互联网 发布:js或且非符号 编辑:程序博客网 时间:2024/06/07 10:33
select temp.*,
       (select sum(pv)
          from (select invest.id,                      
                       (select sum(trunc(f.debt_proportion * l.amount_spare, 2))
                          from
ac_t_ledger_loan@dl.core    l,
                              
ac_t_ledger_finance@dl.core f
                         where l.id = f.loan_id
                           and f.acct_status in (1, 3, 4)
                           and l.acct_status in (1, 3, 4)
                           and f.ledger_id in
                               (select t.id
                                  from
ac_t_ledger@dl.core t
                                 where t.account in
                                       (select t1.acc_id
                                          from ft_t_invest_info t1
                                         where t1.id = invest.id))) as pv
                  from ft_t_invest_info invest
                 where customer_id = 111)) as 总PV
  from (select invest.id,
               (select t.cr_customer_number
                  from
crm_customer@dl.crm t
                 where t.id = invest.customer_id) || '-' ||
               invest.lending_no as 出借编号,
              
               (select NODE_NAME
                  from FT_T_FLOW_DEF c
                 where invest.flow_id = c.node_code) as 流程ID,
              
               (select data_name
                  from sys_t_dictionary b
                 where invest.product_type = b.data_code) as 理财产品,
              
               (select sum(trunc(f.debt_proportion * l.amount_spare, 2))
                  from
ac_t_ledger_loan@dl.core    l,
                      
ac_t_ledger_finance@dl.core f
                 where l.id = f.loan_id
                   and f.acct_status in (1, 3, 4)
                   and l.acct_status in (1, 3, 4)
                   and f.ledger_id in
                       (select t.id
                          from
ac_t_ledger@dl.core t
                         where t.account in
                               (select t1.acc_id
                                  from ft_t_invest_info t1
                                 where t1.id = invest.id))) as pv,
              
               invest.invest_amt as 投资金额
          from ft_t_invest_info invest
         where customer_id = 111) temp;
原创粉丝点击