主要针对 聚合函数 + 多字段的情况
题目一
Find the total number of invoices for each customer along with the customer’s full name, city and email.
像这种题目就不能直在外表中使用聚合函数,而是应该在子查询中使用聚合函数或者窗口函数。
(因为聚合字段不能与非聚合字段放在一起)
SELECT t.FirstName, t.LastName, t.City, t.Email, t.cnt
FROM (
SELECT c.*, COUNT(*) cnt
FROM Customers c
JOIN Invoices i
ON