Retrieve count of total no of answers corresponding to each tag at user level

前端 未结 2 1894
太阳男子
太阳男子 2021-01-29 04:08

I am trying to create a query, to find the count of total number of answers (that I have give in stackoverflow) corresponding to each tag.

Through this, I am able to fin

2条回答
  •  深忆病人
    2021-01-29 05:00

    If you're looking for the COUNT() of your accepted answers for each tag then

    SELECT T.TagName, COUNT(Q.Id) CntAcceptedAnswer
    FROM Posts Q
    JOIN PostTags PT ON Q.Id = PT.PostId
    JOIN Tags T ON T.Id = PT.TagId
    JOIN Posts A ON Q.AcceptedAnswerId = A.Id
    WHERE A.OwnerUserId = 
          AND A.PostTypeId = 2
          AND Q.ClosedDate IS NULL
          AND Q.DeletionDate IS NULL
    GROUP BY T.TagName;
    

    If you're looking for all your answers for each tag then

    SELECT T.TagName, COUNT(A.Id) Cnt
    FROM Posts A 
    JOIN Posts Q ON Q.Id = A.ParentId
    JOIN PostTags PT ON Q.Id = PT.PostId
    JOIN Tags T ON T.Id = PT.TagId
    WHERE A.OwnerUserId = 
    -- You can filter closed and deleted posts here as well if needed
    GROUP BY T.TagName;
    

    UPDATE:

    For your update

    I also need to find url of the questions, title and all the other tags related to that answer.

    You could use the query as a subquery and join it with Posts table to get the other columns as well.

提交回复
热议问题