聚合可能不会出现在WHERE子句中,除非它位于HAVING子句中包含的子查询中 [英] An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause

查看:124
本文介绍了聚合可能不会出现在WHERE子句中,除非它位于HAVING子句中包含的子查询中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT  a.RegNo ,a.Attendance ,COUNT(a.Attendance )AtCount
FROM Attendence as a
 WHERE Attdate BETWEEN '2017-07-17' AND '2017-08-01'and a.Attendance='A' 
group by a.Attendance,a.RegNo   
order by a.Attendance







Msg 147, Level 15, State 1, Line 3
An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.





我尝试过: < br $>




What I have tried:

<pre>
SELECT  a.RegNo ,a.Attendance ,COUNT(a.Attendance )AtCount
FROM Attendence as a
 WHERE Attdate BETWEEN '2017-07-17' AND '2017-08-01'and a.Attendance='A' 
group by a.Attendance,a.RegNo   
order by a.Attendance







Msg 147, Level 15, State 1, Line 3
An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.

推荐答案

请参见此处: [ ^ ]


试试这个

Try this
SELECT  a.RegNo ,a.Attendance ,COUNT(a.Attendance )AtCount
FROM Attendence as a
 WHERE Attdate BETWEEN '2017-07-17' AND '2017-08-01'
group by a.Attendance,a.RegNo   
HAVING a.Attendance='A' 
order by a.Attendance


这篇关于聚合可能不会出现在WHERE子句中,除非它位于HAVING子句中包含的子查询中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆