Last active
June 27, 2017 08:35
-
-
Save atopal/85ec0c9b713c322c3e661df999ce86f5 to your computer and use it in GitHub Desktop.
Number of new documents created per time frame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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/ | |
*/ | |
SELECT DATE_FORMAT(T2.created,'%Y-%m'), count(*) | |
FROM ( | |
SELECT * FROM ( | |
SELECT `wiki_document`.`id` doc, `wiki_revision`.`created`, `wiki_document`.`slug`, `wiki_document`.`locale` | |
FROM `wiki_document` | |
JOIN `wiki_revision` ON `wiki_revision`.`document_id` = `wiki_document`.`id` | |
WHERE `wiki_document`.`modified` >= "2017-01-01 0" | |
AND `wiki_document`.`is_redirect`= 0 | |
AND `wiki_document`.`is_template`= 0 | |
AND `wiki_document`.`deleted`= 0 | |
AND `wiki_document`.`locale`= "en-US" | |
ORDER BY `wiki_document`.`id`, `wiki_revision`.`id` ASC | |
) T1 | |
GROUP BY T1.doc ) T2 | |
WHERE T2.`created` BETWEEN "2017-01-01 0" AND "2018-01-01 0" | |
AND T2.`slug` NOT LIKE "USER%" | |
AND T2.`slug` NOT LIKE "Experiment%" | |
AND T2.`slug` NOT LIKE "Archive%" | |
AND (T2.`slug` LIKE "Web%" | |
OR T2.`slug` LIKE "Learn%" | |
OR T2.`slug` LIKE "Glossary%") | |
GROUP BY DATE_FORMAT(T2.created,'%Y-%m') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment