Skip to content

Instantly share code, notes, and snippets.

@prestigegodson
Created May 3, 2019 13:57
Show Gist options
  • Save prestigegodson/87f377c1e0050d5c6821f795cd4bd6c3 to your computer and use it in GitHub Desktop.
Save prestigegodson/87f377c1e0050d5c6821f795cd4bd6c3 to your computer and use it in GitHub Desktop.
select au.first_name, au.last_name, au.email, p.user_id as "User Id", p.id as "Pledge Id", p.amount as "Pledged Amount",
(select coalesce(sum(pr.amount), 0) from pledge_redemption pr where p.id = pr.pledge_id) as "Paid Amount"
from pledge p
join auth_user au on au.id = p.user_id
where p.amount > (select coalesce(sum(pr.amount), 0) from pledge_redemption pr where p.id = pr.pledge_id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment