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

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 CreationDate
  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)
  )
  SELECT CreationDate,
  CAST(SUM(ViewCount) AS FLOAT)/CAST(COUNT(*) AS FLOAT) AS [Views per question]
FROM tmp
GROUP BY CreationDate
ORDER BY CreationDate

Enter Parameters

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