FAST json extractor, subquery for re-use

1

Please login or register to vote for this query.

(click on this box to dismiss)

Woodworking

Q&A for professional and amateur woodworkers

WITH Raw AS (
  SELECT
    CAST(SUBSTRING(spl.value, 1, CHARINDEX(',', spl.value) - 1) AS INT)
      AS SubjectUserId,
    PostHistory.Id,
    PostHistory.PostHistoryTypeId,
    PostHistory.PostId,
    Posts.OwnerUserId AS ObjectUserId
  FROM PostHistory
  CROSS APPLY STRING_SPLIT(Text, ':') spl
  LEFT JOIN Posts ON PostHistory.PostId = Posts.Id
  WHERE
    PostHistory.PostHistoryTypeId BETWEEN 10 AND 13
    AND
    SUBSTRING(spl.value, 1, 1) BETWEEN '1' AND '9'
),
Raw2 AS (
  SELECT SubjectUserId, ObjectUserId, PostHistoryTypeId, COUNT(*) AS Count
  FROM Raw
  WHERE SubjectUserId <> ObjectUserId
  GROUP BY SubjectUserId, ObjectUserId, PostHistoryTypeId
)
SELECT
  Raw2.SubjectUserId AS [User Link],
  Raw2.ObjectUserId,
  PostHistoryTypes.Name, Raw2.Count
FROM Raw2, PostHistoryTypes
WHERE
  Raw2.PostHistoryTypeId = PostHistoryTypes.Id
ORDER BY Raw2.Count DESC, Raw2.PostHistoryTypeId, Raw2.SubjectUserId

Enter Parameters

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