我有两张桌子,我想计算受访者和总参与者
参与者
ID | Name
-------------
1 David
2 John
3 Mark
4 Jake
申请人
ID | event_id | participant_id
-------------------------------
1 1 1
2 1 2
3 2 3
4 2 1
5 2 2
结果就像这样
报告
ID | event_id | total_respondent | number_of_participant
-------------------------------------------------------
1 1 2 4
2 2 3 4
我的查询是这个..
SELECT Respondent.event_id, COUNT( Respondent.participant_id) as total_respondent
FROM `Respondent`
INNER JOIN participant ON Respondent.participant_id= participant.id
GROUP BY Respondent.event_id
我想在我的查询中包含number_of_participant ..查询应该如何。
答案 0 :(得分:0)
如果您想要两个事件的总参与者数量
,此查询将有所帮助SELECT event_id,
COUNT(participant_id) AS total_resondents,
(SELECT Count(*)
FROM participants) AS participants
FROM respondents
GROUP BY event_id