This topic is locked

Sql code AGE GROUP

6/20/2017 12:08:11 PM
PHPRunner General questions
H
htmalbenur author

Hi I would like you to give me a little clarification on this code, it has done grouping by age range but there is redundancy as you see in the peak, the age range appears twice. I would like to group the sexes and the age groups between them.

thank you
SELECT

Sexe,

CASE WHEN fn_sud.Age BETWEEN 0 AND 9 THEN '0 to 9'

WHEN fn_sud.Age BETWEEN 10 and 19 THEN '10 to 19'

WHEN fn_sud.Age BETWEEN 20 and 29 THEN '20 to 29'

WHEN fn_sud.Age BETWEEN 30 and 39 THEN '30 to 39'

WHEN fn_sud.Age BETWEEN 40 and 49 THEN '40 to 49'

WHEN fn_sud.Age BETWEEN 50 and 59 THEN '50 to 59'

WHEN fn_sud.Age BETWEEN 60 and 69 THEN '60 to 99'

WHEN fn_sud.Age BETWEEN 70 and 79 THEN '70 to 79'

WHEN fn_sud.Age BETWEEN 80 and 89 THEN '80 to 89'

WHEN fn_sud.Age >= 90 THEN '90 +' END AS fn_sud.Age,
COUNT(fn_sud.Age) AS Quantité
FROM fn_sud
WHERE (Sexe ='Masculin' OR Sexe ='Féminin')
GROUP BY fn_sud.Age, fn_sud.Sexe