Skip to content

Instantly share code, notes, and snippets.

@cherring
Created March 18, 2010 00:23
Show Gist options
  • Save cherring/335906 to your computer and use it in GitHub Desktop.
Save cherring/335906 to your computer and use it in GitHub Desktop.
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
Now have this:
find_by_sql(
["SELECT sum(outcomes_13wk_full_outcome_brokered_stream2) as outcomes_13wk_full_outcome_brokered_stream2, sum(outcomes_13wk_full_outcome_brokered_stream3) as outcomes_13wk_full_outcome_brokered_stream3,
sum(outcomes_13wk_full_outcome_brokered_stream4) as outcomes_13wk_full_outcome_brokered_stream4, sum(outcomes_13wk_full_outcome_assisted_stream2) as outcomes_13wk_full_outcome_assisted_stream2,
sum(outcomes_13wk_full_outcome_assisted_stream3) as outcomes_13wk_full_outcome_assisted_stream3, sum(outcomes_13wk_full_outcome_assisted_stream4) as outcomes_13wk_full_outcome_assisted_stream4,
sum(outcomes_13wk_full_outcome_brokered_bonus_stream2) as outcomes_13wk_full_outcome_brokered_bonus_stream2, sum(outcomes_13wk_full_outcome_brokered_bonus_stream3) as outcomes_13wk_full_outcome_brokered_bonus_stream3,
sum(outcomes_13wk_full_outcome_brokered_bonus_stream4) as outcomes_13wk_full_outcome_brokered_bonus_stream4, sum(outcomes_13wk_full_outcome_assisted_bonus_stream2) as outcomes_13wk_full_outcome_assisted_bonus_stream2,
sum(outcomes_13wk_full_outcome_assisted_bonus_stream3) as outcomes_13wk_full_outcome_assisted_bonus_stream3, sum(outcomes_13wk_full_outcome_assisted_bonus_stream4) as outcomes_13wk_full_outcome_assisted_bonus_stream4,
sum(job_placements_brokered_stream2) as job_placements_brokered_stream2, sum(job_placements_brokered_stream3) as job_placements_brokered_stream3,
sum(job_placements_brokered_stream4) as job_placements_brokered_stream4, sum(job_placements_assisted_stream2) as job_placements_assisted_stream2,
sum(job_placements_assisted_stream3) as job_placements_assisted_stream3, sum(job_placements_assisted_stream4) as job_placements_assisted_stream4,
sum(educational_placements_brokered_stream2) as educational_placements_brokered_stream2, sum(educational_placements_brokered_stream3) as educational_placements_brokered_stream3,
sum(educational_placements_brokered_stream4) as educational_placements_brokered_stream4, sum(educational_placements_assisted_stream2) as educational_placements_assisted_stream2,
sum(educational_placements_assisted_stream3) as educational_placements_assisted_stream3, sum(educational_placements_assisted_stream4) as educational_placements_assisted_stream4,
max(outcome_scores.period_ending) as period_ending
FROM outcome_scores JOIN placement_performance_scores ON outcome_scores.scorable_id = placement_performance_scores.scorable_id
WHERE outcome_scores.scorable_id IN (?)
AND outcome_scores.period_ending < (SELECT max(period_ending) from outcome_scores)
ORDER BY period_ending DESC LIMIT 3", outlet_ids]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment