Q&A for Salesforce administrators, implementation experts, developers and anybody in-between
/* How many views per question appears in a given week For instance, is SE more active during the Christmas–NY season or the community do something else? */ DECLARE @All int = ##All:int?1## DECLARE @UsedId int = ##UserId:int## DECLARE @YearsBack int = ##YearsBack:int?1## DECLARE @Month int = ##Month:int?12## DECLARE @DayStart int = ##DayStart:int?20## DECLARE @DayEnd int = ##DayEnd:int?31## ;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-1, CURRENT_TIMESTAMP) AND q.CreationDate < DATEADD("year", -1, CURRENT_TIMESTAMP) AND q.PostTypeId = 1 AND DATEPART("month", q.CreationDate) = @Month AND DATEPART("day", q.CreationDate) >= @DayStart AND DATEPART("day", q.CreationDate) <= @DayEnd ) SELECT CreationDay, CAST(SUM(ViewCount) AS FLOAT)/CAST(COUNT(*) AS FLOAT) AS [Views per question] FROM tmp GROUP BY CreationDay ORDER BY CreationDay