Created
June 20, 2016 00:16
-
-
Save mooreniemi/41dc899a534fa13f062e95b7f3702b5f 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
class SatisfactionQuery | |
def self.execute | |
query = <<-SQL.strip_heredoc | |
SELECT pins.id AS pin_id, pins.satisfaction, procedures.name, surgeons.last_name, | |
dense_rank() OVER ( | |
PARTITION BY procedure_id, surgeon_id | |
ORDER BY pins.satisfaction DESC | |
) AS sat_rank | |
FROM pins | |
INNER JOIN procedures | |
ON procedures.id = pins.procedure_id | |
INNER JOIN surgeons | |
ON surgeons.id = pins.surgeon_id | |
WHERE satisfaction IS NOT NULL; | |
SQL | |
results = [] | |
ActiveRecord::Base.connection.select_all(query).each do |row| | |
results << OpenStruct.new(row) unless row.nil? | |
end | |
results | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment