Skip to content

Instantly share code, notes, and snippets.

@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: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: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: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:6138772
Created August 2, 2013 09:56
Taking a sample for the reports on the forum
SELECT *
FROM `questions_question`
WHERE `questions_question`.`created` > "2013-06-25 0"
AND `questions_question`.`created` < "2013-07-10 0"
AND `questions_question`.`locale` LIKE "en-US"
@atopal
atopal / gist:6002388
Created July 15, 2013 18:51
List articles with no new revision since x
SELECT `wiki_document`.`id`, `wiki_revision`.`created` , `wiki_document`.`slug`, `wiki_document`.`title`
From `wiki_document`
JOIN `wiki_revision` ON `wiki_revision`.`id`=`wiki_document`.`current_revision_id`
WHERE `wiki_revision`.`created` < '2012-07-12'
AND `wiki_document`.`locale` LIKE "en-US"
AND (`wiki_document`.`category` = "10" OR `wiki_document`.`category` = "20")
AND `wiki_document`.`is_archived` = "0"
AND `wiki_revision`.`is_approved` = "1"
AND `wiki_revision`.`content` NOT LIKE "REDIRECT%"
@atopal
atopal / gist:5928005
Created July 4, 2013 13:58
Articles that had to wait more than 30 days for a review
SELECT `wiki_revision`.`summary`, DATEDIFF(`wiki_revision`.`reviewed`,`wiki_revision`.`created`)
FROM `wiki_revision`
JOIN `wiki_document` ON `wiki_document`.`id`=`wiki_revision`.`document_id`
WHERE `wiki_document`.`locale` LIKE 'en-US'
AND `wiki_revision`.`created` >= '2013-01-01'
AND DATEDIFF(`wiki_revision`.`reviewed`,`wiki_revision`.`created`) >=30;
@atopal
atopal / gist:5901428
Created July 1, 2013 14:42
Number of new questions per day
SELECT DATE(`questions_question`.`created`), count(*)
FROM `questions_question`
WHERE DATE(`questions_question`.`created`) > '2012-12-01'
GROUP BY DATE(`questions_question`.`created`)
@atopal
atopal / gist:5901106
Created July 1, 2013 14:10
number of users registering per day
# Shows number users registering per day
SELECT DATE(`auth_user`.`date_joined`), count(*)
FROM `auth_user`
WHERE DATE(`auth_user`.`date_joined`) > '2012-12-01'
GROUP BY DATE(`auth_user`.`date_joined`);
@atopal
atopal / gist:5451547
Last active December 16, 2015 14:49
Top English KB contributors in the last 6 month
SELECT username, count(distinct(document_id)) as reveditnum
FROM
(
SELECT username, document_id
FROM wiki_revision wr
JOIN auth_user au ON wr.creator_id = au.id
JOIN wiki_document wd ON wr.document_id = wd.id
WHERE created > '2012-10-24' and created <= '2013-04-24'
AND wd.locale = 'en-US'
UNION