Skip to content

Instantly share code, notes, and snippets.

@atopal
Last active December 23, 2015 01:38
Show Gist options
  • Select an option

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

Select an option

Save atopal/6561278 to your computer and use it in GitHub Desktop.
Helpful votes from top 10 only
SELECT positive_search_votes.date_created as created_date, positive_search_votes.votes, all_search_votes.votes, (positive_search_votes.votes/all_search_votes.votes*100) as helpful_votes
FROM
(
SELECT DATE(`wiki_helpfulvote`.`created`) as date_created, 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 '2012-07-01 0' AND '2013-10-01 0'
AND (
`wiki_document`.`id` = "817"
OR `wiki_document`.`id` = "735"
OR `wiki_document`.`id` = "816"
OR `wiki_document`.`id` = "901"
OR `wiki_document`.`id` = "9264"
OR `wiki_document`.`id` = "833"
OR `wiki_document`.`id` = "12217"
OR `wiki_document`.`id` = "8191"
OR `wiki_document`.`id` = "761"
OR `wiki_document`.`id` = "729"
OR `wiki_document`.`parent_id` = "817"
OR `wiki_document`.`parent_id` = "735"
OR `wiki_document`.`parent_id` = "816"
OR `wiki_document`.`parent_id` = "901"
OR `wiki_document`.`parent_id` = "9264"
OR `wiki_document`.`parent_id` = "833"
OR `wiki_document`.`parent_id` = "12217"
OR `wiki_document`.`parent_id` = "8191"
OR `wiki_document`.`parent_id` = "761"
OR `wiki_document`.`parent_id` = "729"
)
AND `wiki_helpfulvote`.`helpful` ='1'
GROUP by DATE(`wiki_helpfulvote`.`created`)
) as positive_search_votes
JOIN
(
SELECT DATE(`wiki_helpfulvote`.`created`) as date_created, 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 '2012-07-01 0' AND '2013-10-01 0'
AND (
`wiki_document`.`id` = "817"
OR `wiki_document`.`id` = "735"
OR `wiki_document`.`id` = "816"
OR `wiki_document`.`id` = "901"
OR `wiki_document`.`id` = "9264"
OR `wiki_document`.`id` = "833"
OR `wiki_document`.`id` = "12217"
OR `wiki_document`.`id` = "8191"
OR `wiki_document`.`id` = "761"
OR `wiki_document`.`id` = "729"
OR `wiki_document`.`parent_id` = "817"
OR `wiki_document`.`parent_id` = "735"
OR `wiki_document`.`parent_id` = "816"
OR `wiki_document`.`parent_id` = "901"
OR `wiki_document`.`parent_id` = "9264"
OR `wiki_document`.`parent_id` = "833"
OR `wiki_document`.`parent_id` = "12217"
OR `wiki_document`.`parent_id` = "8191"
OR `wiki_document`.`parent_id` = "761"
OR `wiki_document`.`parent_id` = "729"
)
GROUP by DATE(`wiki_helpfulvote`.`created`)
) as all_search_votes
ON positive_search_votes.date_created=all_search_votes.date_created;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment