Skip to content

Instantly share code, notes, and snippets.

@atopal
Last active December 13, 2015 22:29
Show Gist options
  • Select an option

  • Save atopal/4984994 to your computer and use it in GitHub Desktop.

Select an option

Save atopal/4984994 to your computer and use it in GitHub Desktop.
Number/percentage of forum posts with trouble shooting information per day
SELECT number_of_questions.date_of_question as date_of_question, number_of_questions.number, datapoints.number_of_datapoints, (datapoints.number_of_datapoints/number_of_questions.number) as percentage_of_questions
FROM
(
SELECT DATE(`questions_question`.`created`) as date_of_question, count(*) as number_of_datapoints
FROM `questions_question`
JOIN `questions_questionmetadata` ON `questions_question`.`id`=`questions_questionmetadata`.`question_id`
Where `questions_question`.`created` BETWEEN '2012-01-01 0' AND '2013-02-07 0'
AND `questions_questionmetadata`.`name` LIKE 'troubleshooting'
AND `questions_questionmetadata`.`value` LIKE '%Application Basics%'
GROUP BY DATE(`questions_question`.`created`)
) as datapoints
JOIN
(SELECT DATE(`questions_question`.`created`) as date_of_question, count(*) as number
FROM `questions_question`
Where `questions_question`.`created` BETWEEN '2012-01-01 0' AND '2013-02-07 0'
GROUP BY DATE(`questions_question`.`created`)
) as number_of_questions
ON datapoints.date_of_question=number_of_questions.date_of_question
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment