Skip to content

Instantly share code, notes, and snippets.

@atopal
Created December 23, 2014 11:39
Show Gist options
  • Save atopal/75cdf3e085b205c568cb to your computer and use it in GitHub Desktop.
Save atopal/75cdf3e085b205c568cb to your computer and use it in GitHub Desktop.
Number of upvotes per contributor and product
SELECT `auth_user`.`username`, count(*) as votes
FROM `questions_answer`
JOIN `questions_answervote` ON `questions_answervote`.`answer_id` = `questions_answer`.`id`
JOIN `questions_question` ON `questions_question`.`id` = `questions_answer`.`question_id`
JOIN `auth_user` ON `auth_user`.`id` = `questions_answer`.`creator_id`
WHERE `questions_answervote`.`created` >= '2014-01-01' AND`questions_answervote`.`created` <= '2014-12-01'
AND `questions_question`.`product_id`=2
AND `questions_answervote`.`helpful`=1
GROUP by `questions_answer`.`creator_id` ORDER BY votes DESC limit 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment