Number of bounties with accepted answer depending on the day (time) when bounty started

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?2##

;WITH tmp AS
(SELECT p.Id, p.AcceptedAnswerId AS Acc,
    Period = CASE @Frequency
    WHEN 1 THEN DATEPART("hour", bs.CreationDate)
    WHEN 2 THEN DATEPART("weekday", bs.CreationDate)
    WHEN 3 THEN ROUND((CAST(DATEPART("weekday", bs.CreationDate) AS numeric)
    + CAST(DATEPART("hour", bs.CreationDate) AS numeric) / 24), 2) END
FROM Posts p INNER JOIN Votes bs
    ON p.Id = bs.PostId
    AND bs.VoteTypeId = 8  -- BountyStart
)
SELECT Period, COUNT(*), COUNT(Acc), 
  ROUND((COUNT(Acc))*100.0/(COUNT(*)),2) AS percentage
FROM tmp
GROUP BY Period
ORDER BY Period

Enter Parameters

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