Number of posts/questions/answers depending on the hour in a day

1

Please login or register to vote for this query.

(click on this box to dismiss)

Physical Fitness Meta

Q&A about the site for physical fitness professionals, athletes, trainers, and those providing health-related needs

/*
The usage of Period to switch between daily hours/hour and day in week is borrowed from https://data.stackexchange.com/math/query/155865/best-time-to-ask-questions-on-stackexchange-more-likely-to-get-an-answer
https://meta.stackexchange.com/questions/213603/question-and-answer-activity-on-stack-exchange-interactive-and-customized-editi
*/
DECLARE @Frequency int = ##Frequency:int?3##

;WITH tmp AS
(SELECT Id,
  Period = CASE @Frequency
    WHEN 1 THEN DATEPART("hour", CreationDate)
    WHEN 2 THEN DATEPART("weekday", CreationDate)
    WHEN 3 THEN ROUND((CAST(DATEPART("weekday", CreationDate) AS numeric)
    + CAST(DATEPART("hour", CreationDate) AS numeric) / 24), 2) END
    FROM Posts
  WHERE PostTypeId IN (##types?1,2##))
---types?1,2 both Q&A
---types?1 Q
---types?2 A

SELECT Period, COUNT(*) AS number,
ROUND((COUNT(*)*100.0/(SELECT COUNT(*) FROM tmp)),2) AS percentage
FROM tmp
GROUP BY Period
ORDER BY Period

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results