Q&A for people interested in the history and origins of science and mathematics
/* 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## DECLARE @UserId int = ##UserId:int## ;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 OwnerUserId = @UserId) SELECT Period, COUNT(*) AS number, ROUND((COUNT(*)*100.0/(SELECT COUNT(*) FROM tmp)),2) AS percentage FROM tmp GROUP BY Period ORDER BY Period