'Return the aggregate, rendered as SQL with parameters.'

def as_sql(self, qn, connection):

    params = []
    if hasattr(self.col, 'as_sql'):
        (field_name, params) = self.col.as_sql(qn, connection)
    elif isinstance(self.col, (list, tuple)):
        field_name = '.'.join([qn(c) for c in self.col])
    else:
        field_name = self.col
    substitutions = {'function': self.sql_function, 'field': field_name}
    substitutions.update(self.extra)
    return ((self.sql_template % substitutions), params)
