Skip to content

Instantly share code, notes, and snippets.

@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: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: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: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:bfd6f5cce2ab2701a063
Created October 8, 2014 14:05
top contributors by posts in the forums
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-08-06' and qa.created <= '2014-10-06'
AND NOT qa.creator_id = qq.creator_id
GROUP BY username ORDER BY answernum DESC
@atopal
atopal / gist:b333524d7fc659bfc15c
Created May 9, 2014 16:03
All contributors to Firefox OS articles
SELECT DISTINCT `auth_user`.`username`
FROM (SELECT * FROM `wiki_document_products` WHERE `wiki_document_products`.`product_id` = 4) FirefoxOSdocs
JOIN `wiki_document_contributors` ON `wiki_document_contributors`.`document_id` = FirefoxOSdocs.`document_id`
LEFT JOIN `auth_user` ON `auth_user`.`id` = `wiki_document_contributors`.`user_id`
@atopal
atopal / gist:9272359
Last active August 29, 2015 13:56
A list of all English KB documents by product
SELECT `wiki_document`.`id`, group_concat(DISTINCT `products_product`.`title` SEPARATOR ', ') as 'products', group_concat(DISTINCT `products_topic`.`title` SEPARATOR ', ') as 'topics', `wiki_document`.`title`, `wiki_revision`.`created` as 'last updated'
FROM `wiki_document`
JOIN `wiki_document_products` ON `wiki_document_products`.`document_id` = `wiki_document`.`id`
JOIN `wiki_document_topics` ON `wiki_document_topics`.`document_id` = `wiki_document`.`id`
JOIN `wiki_revision` ON `wiki_revision`.`id`= `wiki_document`.`current_revision_id`
JOIN `products_product` ON `products_product`.`id` = `wiki_document_products`.`product_id`
JOIN `products_topic` ON `products_topic`.`id` = `wiki_document_topics`.`topic_id`
WHERE `wiki_document`.`locale` = "en-US"
GROUP BY `wiki_document`.`id`
@atopal
atopal / gist:8445711
Created January 15, 2014 22:09
Survey results, from below articles
SELECT
all_votes.created_date,
all_votes.votes as all_votes,
FxFeeback_votes.votes as FxFeeback_votes,
didnt_work_votes.votes as didnt_work_votes,
too_long_votes.votes as too_long_votes,
confusing_votes.votes as confusing_votes,
other_votes.votes as other_votes,
round((FxFeeback_votes.votes / all_votes.votes*100),3) as Fx_Feedback_percentage,
round((didnt_work_votes.votes / all_votes.votes*100),3) as didnt_work_percentage,
@atopal
atopal / gist:8302053
Last active January 2, 2016 12:18
Forum status
SELECT
all_questions.created_date,
all_questions.threads as all_threads,
no_replies.threads as not_replied,
needs_attenion.threads as needing_attention,
responded.threads as responded_threads,
solved.threads as solved_threads,
locked.threads as locked_threads,
round((no_replies.threads / all_questions.threads*100),3) as no_replies_percentage,
round((needs_attenion.threads / all_questions.threads*100),3) as ball_dropped_percentage,
@atopal
atopal / gist:6607477
Created September 18, 2013 10:48
Helpfulness by source
SELECT all_votes.created_date , positive_votes.votes as positive_votes, all_votes.votes as all_votes, (positive_votes.votes / all_votes.votes*100) as helpfulness
FROM
(
SELECT DATE(`wiki_helpfulvote`.`created`) as created_date, count(*) as votes
FROM `wiki_helpfulvote`
JOIN `wiki_helpfulvotemetadata` ON `wiki_helpfulvotemetadata`.`vote_id`=`wiki_helpfulvote`.`id`
WHERE `wiki_helpfulvote`.`created` BETWEEN "2012-09-10 0" AND "2012-09-11 0"
AND `wiki_helpfulvotemetadata`.`key` = "referrer"
AND `wiki_helpfulvotemetadata`.`value` LIKE "%.mozilla.org%"
AND `wiki_helpfulvotemetadata`.`value` NOT LIKE "%://support.mozilla.org%"