Skip to content

Instantly share code, notes, and snippets.

@michaelminter
Created September 6, 2013 18:33
Show Gist options
  • Select an option

  • Save michaelminter/6468019 to your computer and use it in GitHub Desktop.

Select an option

Save michaelminter/6468019 to your computer and use it in GitHub Desktop.
Get blog archive by year
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