Created
March 18, 2010 00:32
-
-
Save freshtonic/335909 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
http://skitch.com/railsninja/n4xi5/job-futures | |
Above Url is the interface for the numbers I am trying to pull, Fuck me I have no idea how to try and explain this simply, we have been mindfucking this here for ages | |
1. Is from a table called placement_scores which needs to have numbers from the latest month, period_ending field (date) | |
2. Is also from a table placement_scores but needs to aggregate numbers from the 3 months prior to the latest month | |
3. Is from a table called outcome_scores which needs to aggregate numbers from between 7 months and 5 months prior using a period_ending value as well | |
It looks like 3 separate queries UNIONed together to me, like this: | |
select "Placement targets achieved in #{month_year}", count(*) from placement_scores where .... | |
UNION | |
select "Placement targets achieved #{date_range}", count(*) from placement_scores where.... | |
UNION | |
select "13 Week Outcome Conversion Rate #{blah}", count(*) from outcome_scores where... | |
or the INNER JOIN version (returns 1 row with 6 columns) | |
(obviously you'll need to change the select inner select statements to grab the actual data you want) | |
select | |
r1.message as r1_message, r1.value as r1_value, | |
r2.message as r2_message, r2.value as r2_value, | |
r3.message as r3_message, r3.value as r3_value | |
from | |
(select 'r1 message' as message, 1 as value from dual) as r1 | |
inner join | |
(select 'r2 message' as message, 2 as value from dual) as r2 on 1 = 1 | |
inner join | |
(select 'r3 message' as message, 3 as value from dual) as r3 on 1 = 1 | |
; | |
'dual' is a special virtual table in Postgres (although I think you can leave it out the 'from dual' and I think it will still work). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment