Skip to main content
This query replicates the User Demographics chart in the LearnInk analytics dashboard. It returns a count of active users in the last 90 days, broken down by age bracket and gender.
SELECT 
  age_bracket, 
  COUNT(id) FILTER (WHERE sex = 'female')::int AS female,
  COUNT(id) FILTER (WHERE sex = 'male')::int AS male
FROM users
WHERE age_bracket IN ('18-24', '25-34', '35-44', '45-54', '55-64', '65+')
  AND last_active > current_date - interval '90' day
GROUP BY age_bracket
ORDER BY age_bracket
Notes:
  • Users who have not set an age_bracket or sex are excluded from this query
  • To adjust the activity window, replace '90' day with your preferred interval
  • The results can be charted as a grouped bar chart (age bracket on the x-axis, female/male as the two series)