Reputation: 11
here is table
I would like to get sum of post_count and comment_count. What I did is like this, but does not work.
.select("count(tables.post_count + tables.comment_count) AS field_name").where("field_name >= ?", 3)
Upvotes: 0
Views: 79
Reputation: 536
Try something like this
# Assuming your model is named Table
Table.
select(:id, 'post_count + comment_count AS field_name').
where('post_count + comment_count > 3') # Condition you added at the end of your question
This would return ActiveRecords with two fields:
But I'm not entirely sure this is what you are looking for.
Upvotes: 2