Sql Group By Month Names

To group queries by month name we must use datename function in sql. This function gets two parameter. The first one is interval;for day names we should write dw, for month names we shoul write m or mm. The second parameter is the date parameter. If we want just month index we can use month function too.

Lets we do some example on Library Database

Examples on Library Database

Example 1:List the number of students born each month.

Results Of The Query
Results Of The Query

Example 2:List the number of students born each month ordered by count.

Results Of The Query
Results Of The Query

Example 3:List the number of Mail students born each month ordered by count.

Results Of The Query
Results Of The Query

Example 4: List the Month Names and the taken book count in that month

Results Of The Query
Results Of The Query

Example 5: List the Month Names and the taken book count in that month ordered by book count

or

Results Of The Query
Results Of The Query

Example 6: List the Month Names of 2011 and the taken book count in that month ordered by book count

Results Of The Query
Results Of The Query

Example 7: List the Month Names of 2011 and the taken book count in that month ordered by book count. The Book Count must be bigger then 100

Results Of The Query
Results Of The Query

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: