SQLTeam.com | Weblogs | Forums

Simple Group By Clause Question


#1

Hi guys,

I have a simple group by clause question I can't seem to figure out.

I have a table called Students and a column in that table called StartDate.

I want to return the number students who enrolled in each calendar month over the years to see which months produce the most enrollments.

January 95
February 136
March 72
etc.

The statement below is what I've got but of course this isn't returning the result set I want.... what am I missing?

SELECT COUNT(StudentID) AS Enrolments, DATENAME(Month, StartDate) AS StartMonth
FROM STUDENTS
GROUP BY StartDate

Thanks!


#2

SELECT COUNT(StudentID) AS Enrolments, DATENAME(Month, StartDate) AS StartMonth
FROM STUDENTS
GROUP BY DATENAME(Month, StartDate)
/ORDER BY CAST('01 ' + DATENAME(Month, StartDate) + ' 2000' AS date)/


#3

Perfect! Thanks!

And thanks for the order by snippet. =)