There was a previous question on StackOverflow about this subject (can insert the link, I've got no privileges for the moment) entitled "MySQL date comparison filter", and this goes as an extension of that one.
I've got some authors on my WordPress blog and I would like to get their productivity through MySQL. The next query works pretty well under MySQL to get an author's post during certain time range only one day:
SELECT SQL_CALC_FOUND_ROWS wp_posts.*
FROM wp_posts
JOIN wp_postmeta
ON (wp_posts.ID = wp_postmeta.post_id)
WHERE wp_posts.post_type = 'post'
AND post_author = '50'
AND post_date
BETWEEN STR_TO_DATE('2011-10-27 14:19:17','%Y-%m-%d %H:%i:%s')
AND STR_TO_DATE('2011-10-27 14:51:17','%Y-%m-%d %H:%i:%s')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 100
But it gives me just the posts of that day during that hour range. I'd like to get a table with with everyday data filled up for each day and each author. On each day and each author, there should be the number of posts published by that author on that day and on that hour range.
The output should be something like this:
October Auth1 Auth2 Auth3
1 0 0 0
2 0 0 0
3 0 1 0
4 0 2 0
5 1 0 0
6 0 2 0
7 0 0 0
8 3 0 0
9 0 0 0
10 5 1 0
11 1 0 0
...
31 2 1 1
So the date should be a variable, but I'd like to include all authors, so I'd remove the post_author AND line.
I'm no expert at MySQL but I wonder if this could be done more or less easily and export the query results (or, more exactly, some fields of the query results) as a table, like the one shown.