我想将此问题转移到有效记录中:
我要传输的SQL语句:
SELECT user.name, user.subject
FROM user
INNER JOIN (
SELECT name, COUNT(1) AS occurrences
FROM user
GROUP BY name
) AS user_occurrences
ON user.name = user_occurrences.name
ORDER BY user_occurrences.occurrences DESC, user.name ASC, user.subject ASC
LIMIT 4
How to write this SQL statement?
我可以加入表,但是如何在活动记录中创建新表?谢谢。
答案 0 :(得分:1)
Active Record类的功能非常有限。除了在join方法中编写子查询之外,你无能为力。