2013-08-31 2 views
0

주문 우선 순위에 따라 레코드를 제공하는 다음과 같은 쿼리가 있습니다. 이 전통적인 mySql 쿼리를 레일 ORM으로 변환하고 싶지만 그렇게 할 수는 없습니다.
mySQL 쿼리를 레일 ORM으로 변환하는 방법은 무엇입니까?

SELECT * 
FROM user_questions q 
WHERE question_sequence_number IN (11,13,16,19) 
OR id IN (198,199,200,201,202) 
ORDER BY (question_sequence_number IN (11,13,16,19)) DESC, 
     CASE WHEN question_sequence_number IN (11,13,16,19) 
      THEN question_sequence_number 
      ELSE id 
     END 

이 사람이 나를 도와 주시겠습니까 다음과 같이
내 쿼리는 무엇입니까?

답변

0

결국 나는 혼자서만 글을 쓸 수있었습니다. 위의 쿼리가 레일에 ORM로 변환됩니다은 다음과 같습니다 :

UserQuestion.where("question_sequence_number IN (?) OR id IN (?)", [11,13,16,19], [198,199,200,201,202]).order("question_sequence_number IN (#{[11,13,16,19].join(',')}) DESC, CASE WHEN question_sequence_number IN (#{[11,13,16,19].join(',')}) THEN question_sequence_number ELSE id END") 

감사합니다.

관련 문제