3

これは私のクエリです:

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;

しかし、実行するとエラーが発生します。group by 句を使用して何かを行う必要があることはわかっていますが、それをどこに置くべきかわかりません。

編集:何が間違っていたのかを理解しました:

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;
4

1 に答える 1

2

count集約関数 (または などsum)でない限り、select 句のすべてが group by 句にある必要があります。

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;
于 2012-04-07T16:46:54.010 に答える