如何在子查询中使用Group By

how to use Group By in subquery

select FirstName, LastName

from Customer AS A, Sale AS E

where A.CustomerID=E.CustomerID

AND group by sum(Total)

我总是遇到错误,非常感谢您的帮助!

如果您希望 sum(total) 出现在输出的记录集中,它需要出现在查询的 SELECT 部分。此外,您的语法是倒退的。我们将要分组的字段放在 GROUP BY 中,使用 summaxavg 等函数聚合的字段放在 [= 中12=]。最后,GROUP BY 子句独立存在,不需要 WHERE 子句后的 AND

我相信你想要这样的东西:

select FirstName, LastName, sum(total) as total_sum

from Customer AS A, Sale AS E

where A.CustomerID=E.CustomerID

GROUP BY FirstName, LastName