这里有一个不同的例子,没有别名就不能重写(不能)GROUP BY DISTINCT).想象一张名为purchases记录了customers在…stores也就是说,这是一个对许多表和软件需要知道哪些客户已经在多个商店购买:SELECT DISTINCT customer_id, SUM(1)
FROM ( SELECT DISTINCT customer_id, store_id FROM purchases)
GROUP BY customer_id HAVING 1 < SUM(1);.会因错误而中断Every derived table must have its own alias..修复:SELECT DISTINCT customer_id, SUM(1)
FROM ( SELECT DISTINCT customer_id, store_id FROM purchases) AS custom GROUP BY customer_id HAVING 1 < SUM(1);(注意AS custom化名)。