提交 39449ef9 编写于 作者: A Andrew White 提交者: GitHub

Merge pull request #28183 from eugeneius/having_select_column

Include selects in group query with having clause
......@@ -282,6 +282,7 @@ def execute_grouped_calculation(operation, column_name, distinct) #:nodoc:
operation,
distinct).as(aggregate_alias)
]
select_values += self.select_values unless having_clause.empty?
select_values.concat group_columns.map { |aliaz, field|
if field.respond_to?(:as)
......
......@@ -246,7 +246,8 @@ def test_should_group_by_summed_field_having_condition
end
def test_should_group_by_summed_field_having_condition_from_select
c = Account.select("MIN(credit_limit) AS min_credit_limit").group(:firm_id).having("MIN(credit_limit) > 50").sum(:credit_limit)
skip if current_adapter?(:PostgreSQLAdapter)
c = Account.select("MIN(credit_limit) AS min_credit_limit").group(:firm_id).having("min_credit_limit > 50").sum(:credit_limit)
assert_nil c[1]
assert_equal 60, c[2]
assert_equal 53, c[9]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册