我的作用域如下:
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子句添加约束,使我能够选择where count(bids) > auctions.items_count
发布于 2017-12-16 07:49:37
请参阅http://guides.rubyonrails.org/active_record_querying.html#having
在SQL中要记住的一件事:
由于您的条件使用聚合函数count(),因此您有一个关于结果中包含哪些组的条件。所以它属于HAVING子句。
https://stackoverflow.com/questions/47839821
复制相似问题