我有以下范围:
scope :billable, -> (range_start = nil, range_end = nil) {
joins(:bids)
.where("auctions.complete = 1 AND auctions.starts_at >= ? AND auctions.starts_at <= ? AND auctions.listing = 0", range_start, range_end)
.group("auctions.id")
}
我正在尝试确定如何向where子句添加约束,允许我选择count(bid)> auctions.items count的位置
见http://guides.rubyonrails.org/active_record_querying.html#having
在SQL中要记住:
您有条件要在结果中包含哪些组,因为您的条件使用聚合函数count()
。所以它属于HAVING子句。