Anton.Sandbox

1

Please login or register to vote for this query.

(click on this box to dismiss)

Skeptics Meta

Q&A about the site for scientific skepticism

DECLARE @All int = ##All:int?1##
DECLARE @Frequency int = ##Frequency:int?3##
DECLARE @UsedId int = ##UserId:int##
DECLARE @YearsBack int = ##YearsBack:int?1##

;WITH tmp AS
(
  SELECT q.ViewCount, DATEPART("day", q.CreationDate) as CreationDay
  FROM Posts q
  WHERE q.OwnerUserId = CASE WHEN @All = 1 THEN q.OwnerUserId ELSE @UsedId END
    --AND q.CreationDate > DATEADD("year", -@YearsBack, CURRENT_TIMESTAMP)
    AND q.PostTypeId = 1
    AND DATEPART("week", q.CreationDate) IN (51, 52, 1, 2)
  )
  SELECT CreationDay,
  CAST(SUM(ViewCount) AS FLOAT)/CAST(COUNT(*) AS FLOAT) AS [Views per question]
FROM tmp
GROUP BY CreationDay
ORDER BY CreationDay

Enter Parameters

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