【问题标题】:Sql to Rails Query association, joins and order_bySql 到 Rails 查询关联、连接和 order_by
【发布时间】:2014-10-30 06:40:44
【问题描述】:

我想将 sql 查询转换为 rails 查询

SQL:

select count(*),created_atfrom subscriptions whereaccount_id= (select id fromaccountswheregoogle_domainIS NOT NULL) GROUP BYcreated_atORDER BYcreated_atDESC;

我试过了,但没有得到确切的结果。

我的部分解决方案::

Subscription.joins(:account).where('accounts.google_domain is not null').count

这里我不知道如何使用 group 和 order by。

如果需要任何信息,请发表评论。提前致谢

【问题讨论】:

    标签: mysql join ruby-on-rails-4 associations rails-activerecord


    【解决方案1】:

    Subscription.joins(:account).order("你的需要").group("你的需要").where("accounts.google_domain IS NOT NULL").count

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-18
      • 2015-06-05
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-08
      相关资源
      最近更新 更多