Q&A for Ubuntu users and developers
/* BEST TIME TO ASK QUESTIONS
The best time here is when the delay between a question and an accepted
answer is shortest.
On the graph, look for the value on the x-scale that
corresponds to the minimum value on y-scale.
That's the best time as defined above.
As for Dec 2013, the smallest time-to-answer was for questions asked
on Saturday at 1pm GMT. The asker had to wait only for 78 minutes.
DECLARE @Frequency int = ##Frequency:int?3##
DECLARE @MaxTimeDiff int = ##MaxTimeDiff:int?1440##
DECLARE @All int = ##All:int?1##
DECLARE @UsedId int = ##UserId:int##
DECLARE @MoreStats int = ##MoreStats:int?0##
;WITH tmp AS
SELECT timeDiff = DATEDIFF(minute, q.CreationDate, a.CreationDate),
Period = CASE @Frequency
WHEN 1 THEN DATEPART("hour", q.CreationDate)
WHEN 2 THEN DATEPART("weekday", q.CreationDate)
WHEN 3 THEN ROUND((CAST(DATEPART("weekday", q.CreationDate) AS numeric) +
CAST(DATEPART("hour", q.CreationDate) AS numeric) / 24), 2) END
FROM Posts q
LEFT OUTER JOIN Posts a ON q.AcceptedAnswerId = a.Id
WHERE q.AcceptedAnswerId > 0
AND q.OwnerUserId = CASE WHEN @All = 1 THEN q.OwnerUserId ELSE @UsedId END
AVG(timeDiff) AS [Time to answer]
,CASE WHEN @MoreStats = 1 THEN STDEV(timeDiff) END AS [Time to answer (Standard deviation)]
WHERE ABS(timeDiff) < @MaxTimeDiff
GROUP BY Period
ORDER BY Period