Created
January 9, 2013 22:17
-
-
Save stevencwarren/4497503 to your computer and use it in GitHub Desktop.
This file contains 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 outcomes, inverted_outcomes, sum(outcomes,inverted_outcomes) as goals_met | |
FROM | |
(SELECT Count(outcome_records) FROM "visits" | |
INNER JOIN progress_reports ON progress_reports.visit_id = visits.id | |
INNER JOIN outcome_records ON progress_reports.id = outcome_records.progress_report_id | |
INNER JOIN outcome_goals ON outcome_records.goal_id = outcome_goals.id | |
WHERE ends_on IS NOT NULL | |
AND outcome_records.integer_value IS NOT null | |
AND progress_reports.final is true | |
AND outcome_goals.inverted is false | |
AND outcome_records.integer_value >= outcome_goals.goal) as outcomes, | |
(SELECT Count(outcome_records) FROM "visits" | |
INNER JOIN progress_reports ON progress_reports.visit_id = visits.id | |
INNER JOIN outcome_records ON progress_reports.id = outcome_records.progress_report_id | |
INNER JOIN outcome_goals ON outcome_records.goal_id = outcome_goals.id | |
WHERE ends_on IS NOT NULL | |
AND outcome_records.integer_value IS NOT null | |
AND progress_reports.final is true | |
AND outcome_goals.inverted is true | |
AND outcome_records.integer_value <= outcome_goals.goal) as inverted_outcomes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment