vidya jobin Ответов: 2

Статистическое выражение не может использоваться в предложении 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.


Что я уже пробовал:

<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.

2 Ответов

Рейтинг:
2

Member 12528773

Попробовать это

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