Created
October 13, 2012 09:10
-
-
Save jiripudil/3883912 to your computer and use it in GitHub Desktop.
Select months by presence of entries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# select only those months for which there is at least one entry in the database table | |
# datetime column is DATE or DATETIME | |
SELECT DISTINCT(MONTH(datetime)) AS month, YEAR(datetime) AS year FROM post ORDER BY year, month | |
# returns table with distinct year-month pairs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment