Anton.Sandbox

0

Please login or register to vote for this query.

(click on this box to dismiss)

Portuguese Language

Q&A for linguists, teachers and learners wanting to discuss the finer points of the Portuguese language

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,
         Period = CASE @Frequency
           WHEN 1 THEN DATEPART("hour", q.CreationDate)
           WHEN 2 THEN DATEPART("weekday", q.CreationDate)
           WHEN 3 THEN ROUND((CAST(DATEPART("weekday", q.CreationDate) AS numeric) +
             CAST(DATEPART("hour", q.CreationDate) AS numeric) / 24), 2) END
  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("day", q.CreationDate) = 24
    AND DATEPART("month", q.CreationDate) = 12
  )
  SELECT Period, CAST(SUM(ViewCount) AS FLOAT)/CAST(COUNT(*) AS FLOAT) AS [Views per question]
FROM tmp
GROUP BY Period
ORDER BY Period

Enter Parameters

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