Alternative to 1805782


Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

      TagId   int PRIMARY KEY,
      TagName nvarchar(35)

      INSERT #Tags(TagId, TagName)
      SELECT t.Id, t.TagName
        FROM Tags AS t
         SELECT 1 
           FROM STRING_SPLIT(##CommaSepTags:string##, N',') AS f
          WHERE TRIM(LOWER(f.value)) = t.TagName
    SELECT Tag        = t.TagName,
           Viewed     = SUM(CONVERT(bigint, p.ViewCount)), 
           Questions  = COUNT(p.Id),
           Unanswered = SUM
                          CASE WHEN p.AnswerCount < 1
                          AND p.ClosedDate IS NULL
                          THEN 1 ELSE 0 END
      FROM Posts AS p
     CROSS JOIN #Tags AS t
     WHERE p.PostTypeId = 1 
       AND EXISTS 
             SELECT 1 
               FROM PostTags AS pt
              WHERE pt.PostId = p.Id
                AND pt.TagId  = t.TagId
     GROUP BY t.TagName;

Enter Parameters

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