-1

I need some help with this code of mine. I want to retrieve total counts of registered members for every event they registered in. I hope someone can help me with this. Thank you in advance.

Here's my code:

SELECT *, COUNT(*) as TotalAttendee 
from activities 
join projectcode on activities.projects_id = projectcode.projects_id
join participants on participants.act_id = activities.id
where activities.projects_id='1001' 
order by YEAR(activities.activity_date) desc

This is should be the output

+------------+----------------+
|Event Title |Total Attendees |
+------------+----------------+
|Event 1     | 110            |
+------------+----------------+
|Event 2     | 90             |
+------------+----------------+
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

1 Answers1

0

From your question and the explanation in comments; I can understand;

The output you want to achieve is how many participants in every activity.

This can be achieved by group by in mysql.

Also, Use backticks to surround your output column_names

SELECT act.event_title_column as `Event Title`, COUNT(*) as `Total Attendees`
FROM activities act
JOIN projectcode pr ON act.projects_id = pr.projects_id
JOIN participants pts ON pts.act_id = act.id
WHERE act.projects_id = '1001'
GROUP BY act.id
ORDER BY YEAR(act.activity_date) DESC;
Tushar
  • 3,527
  • 9
  • 27
  • 49