DATE_SUB(CURDATE(),INTERVAL 12 MONTH) GROUP BY shop_user_role ORDER BY volunteer_hours DESC; +----------------+-----------------+--------+-------+ | shop_user_role | unique_visitors | visits | hours | +----------------+-----------------+--------+-------+ | Personal | 141 | 303 | 679 | | Shopping | 61 | 66 | 48 | +----------------+-----------------+--------+-------+ SELECT shop_user_role, COUNT(DISTINCT shop_hours.contact_id) as unique_visitors, COUNT(shop_hours.contact_id) as visits, ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS hours FROM shop_hours LEFT JOIN contacts ON shop_hours.contact_id = contacts.contact_id LEFT JOIN shop_user_roles ON shop_hours.shop_user_role = shop_user_roles.shop_user_role_id WHERE shop_user_roles.volunteer = 0 AND shop_user_roles.other_volunteer = 0 AND time_in > DATE_SUB(CURDATE(),INTERVAL 12 MONTH) GROUP BY shop_user_role ORDER BY hours DESC; +-------------------+------------------+-----------------+ | unique_volunteers | volunteer_visits | volunteer_hours | +-------------------+------------------+-----------------+ | 114 | 778 | 2676 | +-------------------+------------------+-----------------+ SELECT COUNT(DISTINCT shop_hours.contact_id) as unique_volunteers, COUNT(shop_hours.contact_id) as volunteer_visits, ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS volunteer_hours FROM shop_hours LEFT JOIN contacts ON shop_hours.contact_id = contacts.contact_id LEFT JOIN shop_user_roles ON shop_hours.shop_user_role = shop_user_roles.shop_user_role_id WHERE shop_user_roles.volunteer = 1 OR shop_user_roles.other_volunteer = 1 AND time_in > DATE_SUB(CURDATE(),INTERVAL 12 MONTH); +-----------------+--------+-------+ | unique_visitors | visits | hours | +-----------------+--------+-------+ | 188 | 369 | 727 | +-----------------+--------+-------+ SELECT COUNT(DISTINCT shop_hours.contact_id) as unique_visitors, COUNT(shop_hours.contact_id) as visits, ROUND(SUM(HOUR(SUBTIME( TIME(time_out), TIME(time_in))) + MINUTE(SUBTIME( TIME(time_out), TIME(time_in)))/60)) AS hours FROM shop_hours LEFT JOIN contacts ON shop_hours.contact_id = contacts.contact_id LEFT JOIN shop_user_roles ON shop_hours.shop_user_role = shop_user_roles.shop_user_role_id WHERE shop_user_roles.volunteer = 0 AND shop_user_roles.other_volunteer = 0 AND time_in > DATE_SUB(CURDATE(),INTERVAL 12 MONTH); */ ?>
Volunteers
Shop Roles
Unique Volunteers
Volunteer Visits
Volunteer Hours