SELECT
CASE
WHEN TIMESTAMPDIFF(YEAR, CURDATE(), cd.DateOfBirth) < 21 THEN 'Under 20'
WHEN TIMESTAMPDIFF(YEAR, CURDATE(), cd.DateOfBirth) < 31 THEN '21-30'
WHEN TIMESTAMPDIFF(YEAR, CURDATE(), cd.DateOfBirth) < 41 THEN '31-40'
WHEN TIMESTAMPDIFF(YEAR, CURDATE(), cd.DateOfBirth) < 51 THEN '41-50'
ELSE '50+'
END AS Age_Group,
CASE
WHEN TIMESTAMPDIFF(year, curdate(), pd.YearOfLaunch) <5 THEN "<5"
WHEN TIMESTAMPDIFF(year, curdate(), pd.YearOfLaunch) <10 THEN "5-10"
WHEN TIMESTAMPDIFF(year, curdate(), pd.YearOfLaunch) <20 THEN "10-20"
WHEN TIMESTAMPDIFF(year, curdate(), pd.YearOfLaunch) <30 THEN "20-30"
ELSE "30+"
END AS ShoeAge,
ft.Sales
FROM
FactTable ft
JOIN ProductDimension pd ON pd.ProductID = ft.ProductID
JOIN CustomerDimension cd ON cd.CustomerID = ft.CustomerID
GROUP BY AgeGroup, ShoeAge
ORDER BY AgeGroup;