Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- cus.tin,
- lt.sum_portfolio as portfolio,
- case when (sum(lt.sum_portfolio) over())=0 then null
- else (round(100*lt.sum_portfolio/sum(lt.sum_portfolio) over(), 2) || '%') end as "%"
- from tbl_customer as cus
- inner join (select sum(
- case when type = 'loan' then amount
- when type = 'loan_repayment' then -1*amount
- when type = 'interest' then amount
- when type = 'interest_repayment' then -1*amount
- end
- ) as sum_portfolio,
- customer_id
- from tbl_loan_transaction
- group by customer_id
- ) lt on (cus.id = lt.customer_id)
- where lt.sum_portfolio is not null
- group by cus.tin, lt.sum_portfolio
- order by lt.sum_portfolio desc;
Add Comment
Please, Sign In to add comment