Skip to content

Instantly share code, notes, and snippets.

@atopal
atopal / gist:6140708
Created August 2, 2013 15:20
number of distinct kb editors
SELECT DATE(`wiki_revision`.`created`), count(distinct(`wiki_revision`.`creator_id`)
FROM `wiki_revision`
WHERE `wiki_revision`.`created` > "2013-07-01 0"
AND `wiki_revision`.`created` < "2013-08-01 0"
GROUP BY DATE(`wiki_revision`.`created`)
@atopal
atopal / gist:6561278
Last active December 23, 2015 01:38
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"
@atopal
atopal / gist:6592798
Created September 17, 2013 10:53
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'
@atopal
atopal / gist:6599363
Created September 17, 2013 19:21
Helpful vote share by source
SELECT all_votes.created_date , google_votes.votes as google_votes, all_votes.votes as all_votes, (google_votes.votes / all_votes.votes*100) as google_share
FROM
(
SELECT DATE(`wiki_helpfulvote`.`created`) as created_date, count(*) as votes
FROM `wiki_helpfulvote`
WHERE `wiki_helpfulvote`.`created` BETWEEN "2012-08-01 0" AND "2013-10-03 0"
GROUP BY DATE(`wiki_helpfulvote`.`created`)
) as all_votes
JOIN
@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%"
@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: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: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: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: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