Users and Organization
Views for user records and organizational labels used for filtering and grouping across all modules.
Last updated
Views for user records and organizational labels used for filtering and grouping across all modules.
Last updated
SELECT
u.first_name || ' ' || u.last_name AS name,
u.email,
MAX(CASE WHEN ul.label_category = 'Department' THEN ul.label_value END) AS department,
MAX(CASE WHEN ul.label_category = 'Site' THEN ul.label_value END) AS site
FROM reporting.users u
LEFT JOIN reporting.users_labels ul USING (user_id)
WHERE u.is_active = true
GROUP BY u.user_id, u.first_name, u.last_name, u.email
ORDER BY u.last_name;SELECT
ul.label_value AS department,
COUNT(DISTINCT ul.user_id) AS headcount
FROM reporting.users_labels ul
JOIN reporting.users u USING (user_id)
WHERE ul.label_category = 'Department'
AND u.is_active = true
GROUP BY ul.label_value
ORDER BY headcount DESC;