Calendar Queries
This page is a collection of useful queries to run on the Calendar database to get statistical insight to DMS. None of these queries alone contain personal or sensitive information, however the results definitely will.
Most popular classes, with date and length of class
Section titled “Most popular classes, with date and length of class”SELECT e.name, COUNT(r.id) AS attendance,e.event_start, TIMESTAMPDIFF(MINUTE, e.event_start, e.event_end) AS `length`FROM `events` eLEFT JOIN registrations r ON r.event_id = e.idGROUP BY e.idORDER BY attendance DESCAverage attendances of classes, and number of classes, by room, by year / month
Section titled “Average attendances of classes, and number of classes, by room, by year / month”SELECT DATE_FORMAT(e.event_start, "%Y-%m") AS yearmonth, r.name, COUNT(e.id) AS classes, COUNT(reg.id) / COUNT(DISTINCT reg.event_id) as avg_attendanceFROM `events` eLEFT JOIN registrations reg on reg.event_id = e.idLEFT JOIN rooms r ON r.id = e.room_idWHERE e.event_start < NOW()GROUP BY DATE_FORMAT(e.event_start, "%Y-%m"),r.nameORDER BY yearmonth DESCHonorarium / Class Fees for a Committee
Section titled “Honorarium / Class Fees for a Committee” select e.id, e.name, e.event_start, e.cost as "Class Fee", (select count(*) from registrations r where r.event_id = e.id and r.`type` = "paid") * e.cost as "Total Class Fees", e.`status`, IF(h.pay_contact = 1, 50.00, 0.00) as "Honorarium Teacher Amount", IF(h.id is null, 0.00, IF(h.pay_contact = 1, 50.00, 100.00)) as "Honorarium Committee Amount", c.name as "Honorarium Committee" from events e left join honoraria h on h.event_id = e.id left join committees c on c.id = h.committee_id where h.committee_id = 1 and e.`status` IN ("approved", "completed") order by e.event_start desc;Migrated from the legacy DMS wiki: original page