그래서 나는 투표를 기반으로 가장 인기있는 게시물을 얻기 위해 사용하고 있는데이 글의 각 그들에게 링크가이 SQL 쿼리 ..SQL 쿼리는 레일에서 가장 인기있는 게시물을 얻을 수
I이 고유 한 링크가 있고 가장 높은 득표를 가진 게시물 만 얻고 싶습니다. 더 자세한 infomrations없이
ListsPost.find_by_sql("SELECT distinct lists_posts.*,
COALESCE(rs_reputations.value, 0) AS votes FROM \"lists_posts\" LEFT JOIN rs_reputations ON
lists_posts.id = rs_reputations.target_id AND rs_reputations.target_type = 'ListsPost' AND
rs_reputations.reputation_name = 'votes' AND rs_reputations.active = 't' ORDER BY votes desc, lists_posts.updated_at desc")
거의 작동하는 것처럼 보입니다. 문제는, 각 lists_posts는 그 안에 게시물이 있습니다. 나는 같은 게시물을 가진 lists_posts를 찾고 싶지만, 가장 높은 투표를 가진 사람 만 반환하고 싶습니다. –