Hi,
I have a table named by article which has some fields. Currently, I meant by two fields, id which is an auto incremental int and pub_date which is datetime.
I want to have an SQL query that selects month and the count of articles in each month. I have wrote the following SQL to do this task:
SELECT DISTINCT(MONTH(article.pub_date)), COUNT(a.id)
FROM article, article as a
WHERE MONTH(article.pub_date) = MONTH(a.pub_date)
GROUP BY article.pub_date
The above query do the task. However, I think that its performance is very weak. In other word it takes relatively long time.
My question is there any other alternative query to do this task?