Skip to content

Instantly share code, notes, and snippets.

@rlr
Created January 8, 2013 21:23
Show Gist options
  • Save rlr/4488088 to your computer and use it in GitHub Desktop.
Save rlr/4488088 to your computer and use it in GitHub Desktop.
SQL for questions answered in 72hours
SELECT
(extract( year from created )) AS `year`,
(extract( day from created )) AS `day`,
(extract( month from created )) AS `month`,
COUNT(`questions_question`.`created`) AS `count`
FROM `questions_question`
INNER JOIN `auth_user`
ON (`questions_question`.`creator_id` = `auth_user`.`id`)
WHERE (`auth_user`.`is_active` = 1
AND `questions_question`.`created` >= '2011-01-01 00:00:00'
AND `questions_question`.`id`
IN (SELECT U0.`question_id` FROM `questions_answer` U0 INNER JOIN `questions_question` U1 ON (U0.`question_id` = U1.`id`) WHERE U0.`created` < (U1.`created` + INTERVAL '3 0:0:0:0' DAY_MICROSECOND)))
GROUP BY
(extract( year from created )),
(extract( day from created )),
(extract( month from created ))
ORDER BY `questions_question`.`updated` DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment