Skip to content

Instantly share code, notes, and snippets.

@prestigegodson
Last active April 16, 2019 09:38
Show Gist options
  • Save prestigegodson/ea7a30b845f61316b0b87dac0ff99f44 to your computer and use it in GitHub Desktop.
Save prestigegodson/ea7a30b845f61316b0b87dac0ff99f44 to your computer and use it in GitHub Desktop.
Philip
select pr.id, coalesce(acc_bal.balance,0.00) as "Amount Paid",
pr.title as "Project Title",
(select coalesce(sum(amount),0.00) from pledge where project_id = pr.id) as "Amount Pledged",
(select count(*) from pledge where project_id = pr.id) as "Pledge count",
(select count(*) from account_history where account_id = acc.id) as "Payment count"
from project pr
join account acc
on pr.id = acc.project_id
left join account_balance acc_bal
on acc.id = acc_bal.account_id
where pr.is_deleted = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment