Select a month of every year

Post Reply
mister_v
Posts: 195
Joined: Thu Mar 04, 2010 9:19 pm

Select a month of every year

Post by mister_v »

Hello,

I'm creating a select-query to get the data of a specific month of every year.
So not just one month, but all the months december of 2006, 2007, 2008, ...

How do I do that?
chris
Site Admin
Posts: 202
Joined: Mon Jul 21, 2008 9:52 am

Re: Select a month of every year

Post by chris »

You can just compare the month part of the date-field.
But it is different on every Database Management System.

In MySQL, you can use something like this:

Code: Select all

SELECT date,otherfields FROM table WHERE month(date)=12;
more info: http://dev.mysql.com/doc/refman/5.7/en/ ... tions.html

On SQL-server:

Code: Select all

SELECT date,otherfields FROM table WHERE DATEPART(mm,date)=12;
More info : http://www.w3schools.com/sql/func_datepart.asp

I don't have much experience with PostgresSQL, Oracle and others;
But they probably have something similar.
Post Reply