我收到了不明確定義的列。輸入這個SQL語句後。 我想要做的是計算BusinessEventInvite和EventInvite之間參加每個事件的人數。從不同的表中計數2個相同的屬性
SELECT DISTINCT E.EVENTID, Count(EI.Attended)+Count(BEI.Attended) as TotalAttended
FROM EVENT E
left outer join BUSINESSEVENTINVITE BEI ON E.EVENTID= BEI.eventid
left outer join EVENTINVITE EI on EI.EVENTID = E.EVENTID
WHERE EI.ATTENDED = Attended and BEI.ATTENDED = Attended
GROUP BY E.EVENTID
ORDER BY E.EVENTID ASC;
BEI表
ALUMNIID EVENTID RSVP ATTENDED
1 6 YES Attended
2 6 YES Attended
3 6 YES Attended
4 6 YES Attended
5 6 YES Attended
6 6 NO
6行選擇
EI表 ALUMNIID EVENTID RSVP ATTENDED
7 6 YES Attended
8 6 YES Attended
9 6 No
10 7 YES Attended
11 8 YES Attended
12 7 YES Attended
13 7 YES Attended
14 8 YES Attended
15 7 YES Attended
16 8 YES Attended
個10行中選擇
事件表
EVENTID EVENTNAME
6 Annual Social Night
7 Annual Social Night
8 Annual Social Night
9 Annual Social Night
我假設您擁有BUSINESSEVENTINVITE和EVENTINVITE中的同一個人,並在您的查詢中計算了兩次。你想要這個人數一兩次嗎? –
每個人都擁有一個唯一的ID,因此不可能有2個相同的記錄。 –