Wed Feb 15 2017
Copied to clipboard! Copy reply
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
select guid, first_name, created_at,
case when truncate(datediff(curdate(), birth_date)/365, 0) >= '0' and truncate(datediff(curdate(), birth_date)/365, 0) <=17 then 'under 18'
when truncate(datediff(curdate(), birth_date)/365, 0) > '18' and truncate(datediff(curdate(), birth_date)/365, 0) <=24 then '18-24'
when truncate(datediff(curdate(), birth_date)/365, 0) > '24' and truncate(datediff(curdate(), birth_date)/365, 0) <=34 then '25-34'
when truncate(datediff(curdate(), birth_date)/365, 0) > '34' and truncate(datediff(curdate(), birth_date)/365, 0) <=44 then '35-44'
when truncate(datediff(curdate(), birth_date)/365, 0) > '44' and truncate(datediff(curdate(), birth_date)/365, 0) <=54 then '45-54'
when truncate(datediff(curdate(), birth_date)/365, 0) > '54' and truncate(datediff(curdate(), birth_date)/365, 0) <=64 then '55-64'
when truncate(datediff(curdate(), birth_date)/365, 0) > '64' and truncate(datediff(curdate(), birth_date)/365, 0) <=110 then '65+'
end as age_group
from users
where contains (created_at, '"2016" OR "2017"')
group by guid