Skip to content

Instantly share code, notes, and snippets.

@rpavlovic
Created January 29, 2015 14:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpavlovic/d7699dd92daa424ddcce to your computer and use it in GitHub Desktop.
Save rpavlovic/d7699dd92daa424ddcce to your computer and use it in GitHub Desktop.
Wordpress SQL: average comments per day over time
SELECT
'2010-11-24' AS date_begin,
'2015-01-26' AS date_end,
day_of_week,
AVG(comment_count) AS average_comments
FROM (
SELECT
comment_date,
DAYNAME(comment_date) day_of_week,
DAYOFWEEK(comment_date) day_num,
TO_DAYS(comment_date) date,
COUNT(*) AS comment_count
FROM
wp_comments
GROUP BY
comment_date
) temp_table
WHERE
comment_date >= '2010-11-24'
AND
comment_date < '2015-01-27'
GROUP
BY day_of_week
ORDER
BY day_num;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment