$db = \XF::db();
$db->fetchAll("SELECT
xf_user_field_value.user_id,
xf_user.avatar_date,
xf_user.username,
max(.........) as event_date,
substring_index(............................) as event_name
FROM xf_user_field_value
LEFT JOIN xf_user ON xf_user_field_value.user_id = xf_user.user_id
WHERE xf_user_field_value.field_id IN (..................) AND
xf_user_field_value.field_value > DATE_SUB(........................)
GROUP BY xf_user_field_value.user_id
ORDER BY event_date DESC
LIMIT 12");