Column is not valid in select list because it is not contained in either an aggregate function or the GROUP BY clause of SQL Server

This is my request:

SELECT r.CALLID  AS MultiRES,
c.CallDate AS CallDate,
cr.Institution AS Institution,
cr.Branch AS Branch
FROM tblResolution r
INNER JOIN tblcall c ON c.CallID=c.CallID AND c.CallDate=c.CallDate
INNER JOIN tblCaller cr ON cr.Institution = cr.Institution AND cr.Branch=cr.Branch
GROUP BY r.CALLID HAVING COUNT(*) > 1;

      

But I get an error when I run it, I know I need to do something with the group by clause, I just don't know where to put it.

EDIT: just figured out what's wrong:

SELECT r.CALLID  AS MultiRES,
c.CallDate AS CallDate,
cr.Institution AS Institution,
cr.Branch AS Branch
FROM tblResolution r
INNER JOIN tblcall c ON c.CallID=c.CallID AND c.CallDate=c.CallDate
INNER JOIN tblCaller cr ON cr.Institution = cr.Institution AND cr.Branch=cr.Branch
GROUP BY c.CallDate,cr.Institution,cr.Branch, r.CALLID HAVING COUNT(*) > 1;

      

+3


source to share


1 answer


Everything in the select clause must be in a group by clause unless it is an aggregate function (like count

or sum

):



SELECT r.CALLID  AS MultiRES,
c.CallDate AS CallDate,
cr.Institution AS Institution,
cr.Branch AS Branch
FROM tblResolution r
INNER JOIN tblcall c ON c.CallID=c.CallID AND c.CallDate=c.CallDate
INNER JOIN tblCaller cr ON cr.Institution = cr.Institution AND cr.Branch=cr.Branch
GROUP BY r.CALLID, c.CallDate, cr.Institution, cr.Branch
HAVING COUNT(*) > 1;

      

+2


source







All Articles