Hi,
My SQL statement currently reads through customers' birth dates and figures out how old they are. As a test, I'm currently just grouping them in a group 1 through 5. This works... my program indicates the age of each customer and determines which age grouping they're in. But I actually don't need the detail... I would just like to know how many customers are in each age grouping. So I need to increment a counter for each age group, and this is what I don't know how to do. I would like my result to be a summary and look something like this:
So this is just a hypothetical result showing how many customers are in each age group. As a bonus, it would be nice to know the percentage each of those counts made up of the total, but I'm sure that would be harder.
Here is my SQL statement currently that lists every account and their age and age group:
So, how to see how many customers are in each group and just present that summary? Your help would be appreciated.
My SQL statement currently reads through customers' birth dates and figures out how old they are. As a test, I'm currently just grouping them in a group 1 through 5. This works... my program indicates the age of each customer and determines which age grouping they're in. But I actually don't need the detail... I would just like to know how many customers are in each age grouping. So I need to increment a counter for each age group, and this is what I don't know how to do. I would like my result to be a summary and look something like this:
Group 1 | 768 |
Group 2 | 4252 |
Group 3 | 7965 |
Group 4 | 6815 |
Group 5 | 4678 |
Here is my SQL statement currently that lists every account and their age and age group:
Code:
with bdays as ( select Acct, int((Current_Date - date(trim(char(CC)) concat trim(char(YY)) concat '-' concat trim(char(MM)) concat '-' concat trim(char(DD))))/10000) as Age from MyCusts) select Acct, Age, case when Age between 18 and 25 then 'Group 1' when Age between 26 and 35 then 'Group 2' when Age between 36 and 50 then 'Group 3' when Age between 51 and 65 then 'Group 4' when Age >= 66 then 'Group 5' end as Group from bdays
Comment