SELECT
  substring(session.distinct_id SIMILAR '%#"@%#"' ESCAPE '#') AS group,
  event_data.string_value as sim_type,
  COUNT(*)
FROM
  website_event
  JOIN session ON session.session_id = website_event.session_id
  LEFT OUTER JOIN event_data ON event_data.website_event_id = website_event.event_id
WHERE
  website_event.website_id = '16e7d807-4db5-45fd-92a9-27393445a153'
  AND website_event.event_type = 2
  AND website_event.event_name = 'mapster-submit-drifters'
  AND website_event.created_at BETWEEN CURRENT_TIMESTAMP - '7 days'::interval AND CURRENT_TIMESTAMP
  AND session.distinct_id IS NOT NULL
  AND event_data.data_key = 'kind'
GROUP BY
  substring(session.distinct_id SIMILAR '%#"@%#"' ESCAPE '#'),
  event_data.string_value;

