User Activity by UTC Hour

1

Please login or register to vote for this query.

(click on this box to dismiss)

What time of day do I post questions and answers most?

Ask Different

Q&A for power users of Apple hardware and software

-- My Activity by UTC Hour
-- What time of day do I post questions and answers most?

DECLARE @UserID INT = ##UserID?9449426##

-- Create a table containing all the hours in a day (0-24)
SELECT  x.number AS Hours
INTO    #Hours
FROM    master.dbo.spt_values x
WHERE   x.type = 'P'        
AND     x.number <= 23;

-- Get all questions and answers from this user
SELECT *
INTO #MyPosts
FROM Posts
WHERE PostTypeId IN (1, 2)
  AND OwnerUserId = @UserID
  AND CreationDate > Convert(datetime, '2001-01-01')

SELECT
  h.Hours,
  SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS Questions,
  SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS Answers
FROM #Hours h
LEFT JOIN #MyPosts p ON datepart(hour, CreationDate) = h.Hours
GROUP BY h.Hours
ORDER BY h.Hours

Enter Parameters

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