SQL:为什么avg_spent列会收到错误消息,提示该错误不存在?

时间:2018-11-12 01:40:31

标签: group-by having

选择 市, usd_spent / count(city)AS avg_spent 来自travel_spending 按城市分组的avg_spent> 90;

1 个答案:

答案 0 :(得分:0)

某些版本的SQL(例如MySQL)允许在HAVING子句中使用别名,而其他版本(例如SQL Server)则不允许。无论如何,只要在HAVING子句中重复聚合表达式就可以:

SELECT city, AVG(usd_spent) AS avg_spent
FROM travel_spending
GROUP BY city
HAVING AVG(usd_spent) > 90;