diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 9fd6e83..8cb14ea 100644
a
|
b
|
class SQLCompiler(object):
|
115 | 115 | # the select clause are already part of the group by. |
116 | 116 | if is_ref: |
117 | 117 | continue |
118 | | expressions.extend(expr.get_source_expressions()) |
| 118 | expressions.extend( |
| 119 | exp for exp in expr.get_source_expressions() |
| 120 | if not isinstance(exp, Random) |
| 121 | ) |
119 | 122 | having_group_by = self.having.get_group_by_cols() if self.having else () |
120 | 123 | for expr in having_group_by: |
121 | 124 | expressions.append(expr) |