Page 1 of 1
Select a month of every year
Posted: Thu Aug 18, 2016 8:51 pm
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?
Re: Select a month of every year
Posted: Thu Aug 18, 2016 9:23 pm
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.