I have this table
I want to group by age with case and count the gender type
This case:
age <= 20 then 'Group <= 20'
age between 21-40 then 'Group 21-40'
age between 41-60 then 'Group 41-60'
age > 60 then 'Group > 60'
I've tried this code but I get an error:
%%sql
select customer_id, birthdate, extract('year' from current_date) - extract('year' from birthdate ) age
case when age <= 20 then 'Group <= 20'
when age between 21 and 40 then 'Group 21 - 40'
when age between 41 and 60 then 'Group 41 - 60'
else 'Group > 60' end gender
from dim_customer
group by 1
Any solution? Thanks in advance.
BTW: I use this code in Python
