Skip to content

Instantly share code, notes, and snippets.

@atopal
Created September 17, 2013 10:53
Show Gist options
  • Select an option

  • Save atopal/6592798 to your computer and use it in GitHub Desktop.

Select an option

Save atopal/6592798 to your computer and use it in GitHub Desktop.
Helpful votes per article per month
SELECT positive_helpfulvotes.docID as documentID, positive_helpfulvotes.docTitle, positive_helpfulvotes.votes, all_helpfulvotes.votes, (positive_helpfulvotes.votes/all_helpfulvotes.votes*100) as helpful_votes
FROM
(
SELECT `wiki_document`.`id` as docID, `wiki_document`.`title` as docTitle, count(*) as votes
FROM `wiki_helpfulvote`
JOIN `wiki_revision` ON `wiki_helpfulvote`.`revision_id`=`wiki_revision`.`id`
JOIN `wiki_document` ON `wiki_revision`.`document_id`=`wiki_document`.`id`
WHERE `wiki_helpfulvote`.`created` BETWEEN '2013-09-01 0' AND '2013-10-01 0'
AND `wiki_document`.`locale` = 'en-US'
AND `wiki_helpfulvote`.`helpful` ='1'
GROUP BY `wiki_document`.`id` ORDER BY votes DESC
) as positive_helpfulvotes
JOIN
(
SELECT `wiki_document`.`id` as docID, `wiki_document`.`title` as docTitle, count(*) as votes
FROM `wiki_helpfulvote`
JOIN `wiki_revision` ON `wiki_helpfulvote`.`revision_id`=`wiki_revision`.`id`
JOIN `wiki_document` ON `wiki_revision`.`document_id`=`wiki_document`.`id`
WHERE `wiki_helpfulvote`.`created` BETWEEN '2013-09-01 0' AND '2013-10-01 0'
AND `wiki_document`.`locale` = 'en-US'
GROUP BY `wiki_document`.`id` ORDER BY votes DESC
) as all_helpfulvotes
ON positive_helpfulvotes.docID=all_helpfulvotes.docID
ORDER BY all_helpfulvotes.votes DESC LIMIT 100;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment