Created
September 6, 2013 18:33
-
-
Save michaelminter/6468019 to your computer and use it in GitHub Desktop.
Get blog archive by 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 | |
| categories.name, | |
| MONTHNAME( articles.created_at ) AS month_name, | |
| MONTH( articles.created_at ) AS month, | |
| YEAR( articles.created_at ) AS year, | |
| COUNT( articles.id ) as news_count | |
| FROM news_categories categories, news_articles articles | |
| WHERE | |
| articles.published = 1 | |
| AND categories.id = articles.category_id | |
| AND YEAR(articles.created_at) = 2013 | |
| GROUP BY categories.name, month, year | |
| ORDER BY year DESC, month DESC, name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment