Grouping by age
-
sexta-feira, 23 de março de 2012 09:41
Hello, I'm trying to write a SQL command for grouping different age ranges and using them in a chart.
SELECT Unvan, COUNT(*), FLOOR(DATEDIFF(day, Birthdate, GETDATE()) / 365.25) AS Yas FROM Personel WHERE Birthdate BETWEEN '01.01.1978' AND '01.01.1989' GROUP BY Unvan, Birthdate
But this query makes it like below. I want to Combine all those titles and show them like "There is 10 Technician at age 25."
Title - Count - Age
Technician 1 25
Technician 1 25
Technician 2 24
Technician 1 24
Technician 1 24
Technician 1 24
Todas as Respostas
-
sexta-feira, 23 de março de 2012 09:48
SELECT Unvan, COUNT(*) AS Items, Yas FROM ( SELECT Unvan, FLOOR(DATEDIFF(DAY, Birthdate, GETDATE()) / 365.25) AS Yas FROM dbo.Personel WHERE Birthdate BETWEEN '01.01.1978' AND '01.01.1989' ) AS d GROUP BY Unvan, Yas
N 56°04'39.26"
E 12°55'05.63"- Sugerido como Resposta Naomi NMicrosoft Community Contributor, Moderator sexta-feira, 23 de março de 2012 14:03
- Marcado como Resposta KJian_ quinta-feira, 29 de março de 2012 09:04
-
sábado, 24 de março de 2012 16:04
Please know that your calculation of the age will not always return the correct answer.
For more info, see http://gertjans.home.xs4all.nl/sql/calculate-age.html
Gert-Jan

