复合加入查询轨道

时间:2011-03-16 16:14:06

标签: sql ruby-on-rails

SELECT course_categories.course_category_title, COUNT(*) as count
FROM course_enrollments
JOIN courses ON course_enrollments.course_id = courses.course_id
JOIN course_categories ON course_categories.id = courses.course_category_id"
GROUP BY course_categores.id
ORDER BY courses_categories.title

我将如何在rails中执行此操作:(我尝试了以下主要错误)

category_rs = CourseEnrollment.select("course_categories.title, COUNT(*) as count").
            joins(:courses, :course_categories).
            group("course_categories.id").
            order("course_categories.title")

1 个答案:

答案 0 :(得分:0)

我想通了,我需要将连接指定为字符串。