Skip to content

Instantly share code, notes, and snippets.

@atopal
atopal / bcd-signals.sql
Created February 4, 2020 12:21
BCD signals
SELECT `wiki_bcsignal`.`id`, `wiki_bcsignal`.`submitted_at`, `wiki_document`.`locale`,`wiki_document`.`slug`, `wiki_bcsignal`.`browsers`, `wiki_bcsignal`.`explanation`, `wiki_bcsignal`.`feature`, `wiki_bcsignal`.`supporting_material`
FROM `wiki_bcsignal`
JOIN `wiki_document` ON `wiki_bcsignal`.`document_id`=`wiki_document`.`id`
WHERE LENGTH(`wiki_bcsignal`.`explanation`) > 3
@atopal
atopal / editspermonth.sql
Created December 12, 2017 16:49
Edits per month
SELECT DATE_FORMAT(`wiki_revision`.`created`,'%Y-%m'), count(`wiki_revision`.`created`)
From `wiki_revision`
WHERE `wiki_revision`.`created`>="2016-1-1 0"
GROUP BY DATE_FORMAT(`wiki_revision`.`created`,'%Y-%m')
@atopal
atopal / gist:0cc999f57cd9f3c90b1271519940f3e5
Created December 12, 2017 16:45
Contributors per month
SELECT DATE_FORMAT(`wiki_revision`.`created`,'%Y-%m'), count(DISTINCT(`wiki_revision`.`creator_id`))
From `wiki_revision`
WHERE `wiki_revision`.`created`>="2016-1-1 0"
GROUP BY DATE_FORMAT(`wiki_revision`.`created`,'%Y-%m')
@atopal
atopal / guides.sql
Last active May 22, 2017 11:52
Number of all properly tagged English Web reference and guide pages on MDN
SELECT `wiki_document`.`slug`
FROM `wiki_document`
JOIN `wiki_taggeddocument` ON `wiki_taggeddocument`.`content_object_id` = `wiki_document`.`id`
WHERE `wiki_taggeddocument`.`tag_id`=6633 -- Guide
AND `wiki_document`.`locale` = "en-US"
AND `wiki_document`.`is_redirect`= 0
AND `wiki_document`.`is_template`= 0
AND `wiki_document`.`deleted`= 0
AND `wiki_document`.`slug` LIKE "Web/%"
@atopal
atopal / gist:85ec0c9b713c322c3e661df999ce86f5
Last active June 27, 2017 08:35
Number of new documents created per time frame
/*
Creates a list of documents that have been modified within a time frame,
lists all their revisions and takes only the first one, checks whether
the revision is within the time frame and only outputs those docs that have
a first revision within the time frame.
Works because of a bug in mysql:
http://stackoverflow.com/questions/12102200/get-records-with-max-value-for-each-group-of-grouped-sql-results
Proper ways:
https://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/
@atopal
atopal / gist:af1dbc087b31e5837f38b27fa3a9d76a
Created August 26, 2016 10:48
active accounts with Persona but not github credentials
SELECT DISTINCT `auth_user`.`email`, `auth_user`.`first_name`, `auth_user`.`last_name`
FROM
(SELECT *
FROM `socialaccount_socialaccount`
WHERE `socialaccount_socialaccount`.`provider`="persona") A
LEFT JOIN
(SELECT *
FROM `socialaccount_socialaccount`
WHERE `socialaccount_socialaccount`.`provider`="github") B
ON A.`user_id` = B.`user_id`
@atopal
atopal / gist:21bffa9a7f8ef6a8d198953106b4a95f
Last active August 26, 2016 10:44
Number of accounts with Pesona and Github auth
SELECT count(*)
FROM
(SELECT *
FROM `socialaccount_socialaccount`
WHERE `socialaccount_socialaccount`.`provider`="persona") A
INNER JOIN
(SELECT *
FROM `socialaccount_socialaccount`
WHERE `socialaccount_socialaccount`.`provider`="github") B
ON A.`user_id` = B.`user_id`
@atopal
atopal / gist:eaedf01a02862db6a991fd870305bc73
Last active August 2, 2016 14:22
Number of Persona active accounts without Github auth
SELECT count(*)
FROM
(SELECT *
FROM `socialaccount_socialaccount`
WHERE `socialaccount_socialaccount`.`provider`="persona") A
LEFT JOIN
(SELECT *
FROM `socialaccount_socialaccount`
WHERE `socialaccount_socialaccount`.`provider`="github") B
ON A.`user_id` = B.`user_id`
SELECT DISTINCT `questions_answer`.`creator_id`
FROM `questions_answer`
JOIN `users_profile` ON `users_profile`.`user_id` = `questions_answer`.`creator_id`
WHERE `questions_answer`.`created` BETWEEN '2015-07-01 0' AND '2015-10-01 0'
AND `users_profile`.`first_answer_email_sent` = 1
AND
`questions_answer`.`creator_id` NOT IN
(SELECT DISTINCT `auth_user`.`id`
FROM `questions_answer`
JOIN `auth_user` ON `auth_user`.`id` = `questions_answer`.`creator_id`
@atopal
atopal / gist:6958a4d1b72193751eb6
Last active August 29, 2015 14:27
Number of reviewed edits ready for L10n for a certain time frame
SELECT *
FROM `wiki_document`
#JOIN `wiki_document_products` ON `wiki_document`.`id` = `wiki_document_products`.`document_id`
JOIN `wiki_revision` ON `wiki_document`.`id`= `wiki_revision`.`document_id`
WHERE `wiki_document`.`locale`="en-US"
#AND `wiki_document_products`.`product_id` = 1
AND `wiki_document`.`is_archived` = 0
AND `wiki_document`.`current_revision_id` IS NOT NULL
AND `wiki_document`.`html` NOT LIKE '%REDIRECT%'
AND `wiki_revision`.`reviewed`IS NOT NULL