Skip to content

Instantly share code, notes, and snippets.

@nwwells
Created January 15, 2016 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nwwells/55423f9c6c844da205de to your computer and use it in GitHub Desktop.
Save nwwells/55423f9c6c844da205de to your computer and use it in GitHub Desktop.
Purpose Portfolio Giving Reports
SELECT
client.name AS "Company",
ppuser."createdAt" AS "Account Sign-up Timestamp",
"firstName" AS "First Name",
"lastName" AS "Last Name",
"workEmail" AS "Email",
"confirmedAt" AS "Account Confirmation Timestamp",
SUM(engagement.amount) AS "Paycheck Donation Amt / Charity",
portfoliounit.name AS "Charity"
FROM client
INNER JOIN ppuser
ON ppuser.owner = client.id
INNER JOIN engagement
ON ppuser.id = engagement.owner
INNER JOIN opportunity
ON engagement.master = opportunity.id
INNER JOIN portfoliounit
ON opportunity.owner = portfoliounit.id
WHERE
engagement.amount > 0
AND
client.name = 'Experticity'
AND
"deactivatedAt" IS NULL
GROUP BY
client.name,
portfoliounit.id,
ppuser.id
ORDER BY
client.name,
ppuser."createdAt" ASC,
"workEmail" ASC,
portfoliounit.name ASC
SELECT
client.name AS "Company",
ppuser."createdAt" AS "Account Sign-up Timestamp",
"firstName" AS "First Name",
"lastName" AS "Last Name",
"workEmail" AS "Email",
"confirmedAt" AS "Account Confirmation Timestamp",
"payrollDeduction" AS "Total Paycheck Donation Amt"
FROM ppuser
INNER JOIN client
ON ppuser.owner = client.id
WHERE
client.name = 'Experticity'
AND
"deactivatedAt" IS NULL
ORDER BY
client.name,
ppuser."createdAt" ASC,
"workEmail" ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment