Last active
December 22, 2015 11:09
-
-
Save michaelminter/6464001 to your computer and use it in GitHub Desktop.
Get blog archive format of dates by count and grouped by month / year
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 | |
| news_categories.name AS category, | |
| YEAR(news_articles.creation_date) AS year, | |
| MONTH(news_articles.creation_date) AS month, | |
| MONTHNAME(news_articles.creation_date) AS month_name, | |
| COUNT(*) AS total | |
| FROM news_articles | |
| INNER JOIN news_categories ON news_articles.category_id=news_categories.id | |
| WHERE DATE(news_articles.creation_date) >= DATE_SUB(NOW(), INTERVAL 2 YEAR) | |
| GROUP BY category, year, month | |
| ORDER BY year, month, category; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment