Skip to content

Instantly share code, notes, and snippets.

@atopal
atopal / gist:7fc680cd3815ffcb1d50
Last active August 29, 2015 14:10
Get all comments for an article by document ID
SELECT `wiki_helpfulvotemetadata`.`vote_id`, `wiki_helpfulvotemetadata`.`value`
FROM `wiki_revision`
JOIN `wiki_document` ON `wiki_revision`.`document_id` = `wiki_document`.`id`
JOIN `wiki_helpfulvote` ON `wiki_revision`.`id`= `wiki_helpfulvote`.`revision_id`
JOIN `wiki_helpfulvotemetadata` ON `wiki_helpfulvote`.`id` = `wiki_helpfulvotemetadata`.`vote_id`
WHERE `wiki_document`.`id`= "735"
AND `wiki_helpfulvote`.`helpful` = "0"
AND `wiki_helpfulvotemetadata`.`key` = "survey"
AND `wiki_helpfulvotemetadata`.`value` NOT LIKE '%comment": ""%'
AND `wiki_helpfulvote`.`created` BETWEEN '2014-11-01 0' AND '2014-12-01 0'
@atopal
atopal / gist:83837f7e9555069d6a25
Created November 20, 2014 19:31
Get all comments for en-US for a specific date range
SELECT `wiki_document`.`title`,`wiki_helpfulvote`.`created`, `wiki_helpfulvotemetadata`.`value`
FROM `wiki_revision`
JOIN `wiki_document` ON `wiki_revision`.`document_id` = `wiki_document`.`id`
JOIN `wiki_helpfulvote` ON `wiki_revision`.`id`= `wiki_helpfulvote`.`revision_id`
JOIN `wiki_helpfulvotemetadata` ON `wiki_helpfulvote`.`id` = `wiki_helpfulvotemetadata`.`vote_id`
WHERE `wiki_document`.`locale` = "en-US"
AND `wiki_helpfulvote`.`helpful` = "0"
AND `wiki_helpfulvotemetadata`.`key` = "survey"
AND `wiki_helpfulvotemetadata`.`value` NOT LIKE '%comment": ""%'
AND `wiki_helpfulvote`.`created` BETWEEN '2014-11-05 0' AND '2014-11-06 0'
@atopal
atopal / gist:2065624091506c4821a0
Created December 23, 2014 09:47
Top contributors by posts for Firefox for Android questions
SELECT username, count(*) as answernum
FROM questions_question qq
JOIN questions_answer qa ON qa.question_id = qq.id
JOIN auth_user au ON qa.creator_id = au.id
WHERE qa.created >= '2014-01-01' and qa.created <= '2014-12-01 0'
AND qq.`product_id`=2
AND NOT qa.creator_id = qq.creator_id
GROUP BY username ORDER BY answernum DESC limit 100;
@atopal
atopal / gist:d774e7f6624a58f810f4
Created December 23, 2014 11:30
Number of solutions per forum contributor per locale per product
SELECT `auth_user`.`username`, count(*) as solutions
FROM `questions_question`
JOIN `questions_answer` ON `questions_question`.`solution_id`=`questions_answer`.`id`
JOIN `auth_user` ON `questions_answer`.`creator_id`=`auth_user`.`id`
WHERE `questions_answer`.`created` >= '2014-01-01' AND `questions_answer`.`created` <= '2014-12-01'
AND `questions_question`.`product_id`=2
AND `questions_question`.`locale` = 'en-US'
GROUP BY `auth_user`.`id` ORDER by solutions DESC Limit 100;
@atopal
atopal / gist:75cdf3e085b205c568cb
Created December 23, 2014 11:39
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
@atopal
atopal / gist:769f19f01676a97483cf
Last active August 29, 2015 14:21
All English user facing active articles across all products
SELECT `wiki_document`.`id`, `wiki_document`.`title`
FROM `wiki_document`
WHERE `wiki_document`.`locale` = "en-US"
AND `wiki_document`.`is_template` = 0
AND `wiki_document`.`is_archived` = 0
AND (`wiki_document`.`category` = 10 OR `wiki_document`.`category` = 20)
@atopal
atopal / gist:f49794af9a96f4b334fa
Last active August 29, 2015 14:21
All user facing articles across all product and locales
SELECT `wiki_document`.`id`, `wiki_document`.`title`
FROM `wiki_document`
WHERE `wiki_document`.`is_template` = 0
AND `wiki_document`.`is_archived` = 0
AND (`wiki_document`.`category` = 10 OR `wiki_document`.`category` = 20)
@atopal
atopal / gist:2f072f3101c252e2f5e7
Created May 17, 2015 13:23
All edits to the KB over a certain time frame
SELECT `wiki_revision`.`id`
FROM `wiki_revision`
WHERE `wiki_revision`.`created` >= '2015-01-01 0'
AND `wiki_revision`.`created` < '2015-05-01 0'
@atopal
atopal / gist:b1f8e1363385d88c98c7
Created May 17, 2015 13:28
All replies in Army of Awesome for a time frame by month
SELECT `customercare_reply`.`created`, count(*)
FROM `customercare_reply`
WHERE `customercare_reply`.`created` BETWEEN '2015-01-01' AND '2015-05-01'
GROUP BY month(`customercare_reply`.`created`)
@atopal
atopal / gist:920bd2a12909478ddb1b
Created May 17, 2015 13:40
All support forum pots for a certain time frame
SELECT count(*)
FROM `questions_answer`
WHERE `questions_answer`.`created` BETWEEN '2015-01-01' AND '2015-05-01'