The code below works but I'm trying to write it so that only rows when sum(s.quantity) < c.reqtotal are returned
I keep getting :
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.
I can't figure out how to do it
Thanks
Dan
Code:
Select s.curitemid, s.userid, sum(s.quantity) as total, c.ReqTotal , c.description
from studentdata s
Inner Join curriculum c On s.curitemid= c.curitemid
Where userid in(
select userid from users
Where active= 1 and usertype='S'
and class in (select classid from class where enddate > GetDate()
and startdate <= getdate()
and upper(year) NOT Like '%STAFF%' ))
and c.reqtotal > 0
group by s.curitemid, s.userid,c.ReqTotal, c.description
I keep getting :
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.
I can't figure out how to do it
Thanks
Dan