none
Grouping by age

    Pergunta

  • 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

    sexta-feira, 23 de março de 2012 09:41

Respostas

  • 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 NModerator sexta-feira, 23 de março de 2012 14:03
    • Marcado como Resposta KJian_ quinta-feira, 29 de março de 2012 09:04
    sexta-feira, 23 de março de 2012 09:48

Todas as Respostas