我正在使用Microsoft SQL SERVER 2014。
以下是我的查询
SELECT type, SUM(calories) AS total_calories FROM exercise_logs GROUP BY type HAVING total_calories > 150;
我得到了错误
消息207,级别16,状态1,第2行无效的列名称“ total_calories”。
这是一个非常简单的表(我是sql的新手,正在学习它)。有人可以指出我在做什么错吗?谢谢。
Aggregation 是必需的,因为您无权访问别名 total_calories
Aggregation
total_calories
SELECT type,SUM(calories) AS total_calories FROM exercise_logs GROUP BY type HAVING SUM(calories) > 150;