我想将sql查询转换为rails查询
SQL:
选择计数(*),
created_at来自订阅,其中
account_id=(从
帐户其中
google_domain选择ID IS NOT NULL) GROUP BY
created_atORDER BY
created_atDESC;
我尝试了这个,但没有得到确切的结果。
我的部分解决方案::
Subscription.joins(:account).where('accounts.google_domain is not null').count
这里我不知道如何使用分组和排序依据。
如果需要任何信息,请发表评论。提前致谢
最佳答案
Subscription.joins(:account).order("您的需求").group("您的需求").where("accounts.google_domain IS NOT NULL").count
希望对您有帮助
关于mysql - Sql 到 Rails 查询关联、连接和 order_by,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26646596/