Skip to content

Instantly share code, notes, and snippets.

@jaredhoyt
Created September 9, 2010 16:48
Show Gist options
  • Save jaredhoyt/572155 to your computer and use it in GitHub Desktop.
Save jaredhoyt/572155 to your computer and use it in GitHub Desktop.
SELECT "Group".abbr, COUNT("PaymentException".id) AS exception_count, AVG("PaymentException".appeals) AS appeals_average,
SUM("PaymentException".appeal_amount) AS appealed_total, AVG("PaymentException".appeal_amount) AS appealed_average,
AVG(EXTRACT(epoch FROM "PaymentException".created)) AS age_average
FROM exceptions "PaymentException"
INNER JOIN procedures "Procedure" ON "Procedure".id = "PaymentException".procedure_id
INNER JOIN claims "Claim" ON "Claim".id = "Procedure".claim_id
INNER JOIN groups "Group" ON "Group".id = "Claim".group_id
WHERE "PaymentException".appeal_amount > 0
GROUP BY "Group".abbr
ORDER BY "Group".abbr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment