Anton.Sandbox

0

Please login or register to vote for this query.

(click on this box to dismiss)

Ask Ubuntu

Q&A for Ubuntu users and developers

-- The best time to ask questions
-- Look for the minimum value on y-scale:
-- It says when the time between question and answer is minimal.
-- For example

DECLARE @Frequency int = ##Frequency:int?3##
DECLARE @MaxTimeDiff int = ##MaxTimeDiff:int?1440##

;WITH tmp AS
(
  SELECT TOP 1000 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
  )
  SELECT Period,
  sum(case when timeDiff < 0 then 1 else null end) OVER(PARTITION BY Period) as [Negative timeDiff],
    AVG(timeDiff) OVER(PARTITION BY Period) AS [Mean],
    STDEV(timeDiff) OVER(PARTITION BY Period) AS [Standard deviation]
FROM tmp
-- We cut off answers that arrived more than n minutes
-- after the question to avoid outliers
WHERE timeDiff < @MaxTimeDiff
ORDER BY Period

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results