select sum(case
when datediff(year,Birthday,getdate()) between 21 and 30
then 1
else 0
end
) as '21-30'
,sum(case
when datediff(year,Birthday,getdate()) between 31 and 40
then 1
else 0
end
) as '31-40'
,sum(case
when datediff(year,Birthday,getdate()) between 41 and 50
then 1
else 0
end
) as '41-50'
when datediff(year,Birthday,getdate()) between 21 and 30
then 1
else 0
end
) as '21-30'
,sum(case
when datediff(year,Birthday,getdate()) between 31 and 40
then 1
else 0
end
) as '31-40'
,sum(case
when datediff(year,Birthday,getdate()) between 41 and 50
then 1
else 0
end
) as '41-50'