django/django — pull request #3585 by akaariai (2014-11-20 12:30:41+00:00)
Title: Fixed #23877 -- aggregation's subquery missed target col

Aggregation over subquery produced syntactically incorrect queries in
some cases as Django didn't ensure that source expressions of the
aggregation were present in the subquery.