我有三张桌子
Member - MemberID, gender, etc
Venue - VenueID, City, VenueName, etc
Event - EventID, EventDate, etc
试图显示一个查询,该查询显示城市为格拉斯哥的每个事件以及 2012 年 1 月的时间段内的男性和女性人数。
到目前为止我的结果是。
SELECT Venue.VenueName, Venue.City, Event.Eventdate, (select count(gender) from member where gender = 'm') AS MaleTotal, (select count(gender) from member where gender = 'f') AS FemaleTotal
FROM Venue INNER JOIN Event ON Venue.VenueID = Event.FKvenueID
WHERE Venue.City='Glagow' and Month(eventdate)=1 and year(partydate) = 2011;
这会产生一个表格显示
VenueName-ABC Venue, XYZVenue;
City- Glasgow, Glasgow;
Partydate- 04/01/2012, 05/01/2012
MaleTotal-4,4
FemaleTotal-3,3
这是错误的,因为成员表中总共只有 7 个条目,每个条目只参加 1 个活动。
任何建议将不胜感激。