0

i'm trying to sort a query by two conditionals. First query is if the 'percentage' is above 75 and if it's not it will then sort by a 'grade' The percentage belongs in a another table than the grade. for example, the first query could look something like this but would only be for values above '75:

joins(:school_annual_data => :school_eligibility_data).order("GREATEST(school_annual_data.survey3_low_percent, school_eligibility_data.low_income_percent)")

Then the query would look like:

order('school_type ASC')

How can I combine them together?

1 Answer 1

1

You should be able to commas separate them in the same parenthesis.

.order(condition_1 ASC, condition_2 ASC)

So in your case:

.order("GREATEST(school_annual_data.survey3_low_percent, school_eligibility_data.low_income_percent), school_type ASC")

See more: http://apidock.com/rails/ActiveRecord/QueryMethods/order

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, how does this check if the "percent" is a certain number?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.