def cast_avg_to_float(self, compiler, connection):
    """
    Microsoft AVG doesn't cast type by default, but needs to CAST to FLOAT so
    that AVG([1, 2]) == 1.5, instead of 1.
    """
    if getattr(connection, 'cast_avg_to_float', True):
        return self.as_sql(compiler, connection, template='%(function)s(CAST(%(field)s AS FLOAT))')
    return self.as_sql(compiler, connection)