Estimated long-term daily views generated by questions posted at month

1

Please login or register to vote for this query.

(click on this box to dismiss)

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

DECLARE @now DATETIME = (
  SELECT TOP 1 DATEADD(S, 1, CreationDate) FROM Posts ORDER BY Id DESC
);

DECLARE @lastMonth DATETIME = DATEADD(DAY, -30, @now);
SET @lastMonth = DATEFROMPARTS(YEAR(@lastMonth), MONTH(@lastMonth), 1);

SELECT
  DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1) AS Month,
  SUM(86400.0 * ViewCount / DATEDIFF(S, CreationDate, @now)) AS SumViewsPerDay
FROM Posts
WHERE ViewCount IS NOT NULL AND CreationDate < @lastMonth
GROUP BY DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1)
ORDER BY Month DESC

Enter Parameters

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