Views

0

Please login or register to vote for this query.

(click on this box to dismiss)

Mythology

Q&A for enthusiasts and scholars of mythology and folklore

DECLARE @EOM datetime = '2021-09-01'
DECLARE @EOLM datetime = '2021-08-01'

DECLARE @YOY datetime = '2020-08-01'
DECLARE @YTD datetime = '2021-01-01'

DECLARE @UserId int = 158668

SELECT COUNT(DISTINCT A.Id) AS A_YOY
FROM Posts AS A
  INNER JOIN PostTags ON A.ParentId = PostTags.PostId
  INNER JOIN Tags ON PostTags.TagId = Tags.id
WHERE
  A.OwnerUserId = @UserId
  AND A.CreationDate >= @YOY
  AND A.CreationDate < @EOM;

SELECT SUM(Q.ViewCount) AS V_ALL FROM (
  SELECT DISTINCT Q.Id, Q.ViewCount
  FROM Posts AS A
    INNER JOIN PostTags ON A.ParentId = PostTags.PostId
    INNER JOIN Posts AS Q ON A.ParentId = Q.Id
    INNER JOIN Tags ON PostTags.TagId = Tags.id
  WHERE
    A.OwnerUserId = @UserId
    AND (TagName LIKE '%amazon%' OR TagName LIKE '%aws%')
    AND A.CreationDate < @EOM
) as Q
  
SELECT SUM(Q.ViewCount) AS V_12M FROM (
  SELECT DISTINCT Q.Id, Q.ViewCount
  FROM Posts AS A
    INNER JOIN PostTags ON A.ParentId = PostTags.PostId
    INNER JOIN Posts AS Q ON A.ParentId = Q.Id
    INNER JOIN Tags ON PostTags.TagId = Tags.id
  WHERE
    A.OwnerUserId = @UserId
    AND (TagName LIKE '%amazon%' OR TagName LIKE '%aws%')
    AND A.CreationDate >= @YOY
    AND A.CreationDate < @EOM
) as Q

SELECT SUM(Q.ViewCount) AS V_12M_PREV FROM (
  SELECT DISTINCT Q.Id, Q.ViewCount
  FROM Posts AS A
    INNER JOIN PostTags ON A.ParentId = PostTags.PostId
    INNER JOIN Posts AS Q ON A.ParentId = Q.Id
    INNER JOIN Tags ON PostTags.TagId = Tags.id
  WHERE
    A.OwnerUserId = @UserId
    AND (TagName LIKE '%amazon%' OR TagName LIKE '%aws%')
    AND A.CreationDate >= @YOY
    AND A.CreationDate < @EOLM
) as Q

Enter Parameters

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