Last active
October 16, 2017 12:19
-
-
Save feldwebel/0cdd1a548476cdd604316d849ecd8bd5 to your computer and use it in GitHub Desktop.
Percentage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| select c.tin, sum(case when lt.type = any(array['interest', 'loan']) then lt.amount else -lt.amount end) portfolio, | |
| round( | |
| 100.0 | |
| * sum(case when lt.type = any(array['interest', 'loan']) then lt.amount else -lt.amount end) | |
| / (select sum(case when type = any(array['interest', 'loan']) then amount else -amount end) from tbl_loan_transaction) | |
| , 2) "%" | |
| from tbl_loan_transaction lt | |
| join tbl_customer c on c.id = lt.customer_id | |
| group by c.tin | |
| having sum(case when lt.type = any(array['interest', 'loan']) then lt.amount else -lt.amount end) > 0 | |
| order by portfolio desc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment