Question stats by tag

4

Please login or register to vote for this query.

(click on this box to dismiss)

Audio-Video Production Meta

Q&A about the site for engineers, producers, editors, and enthusiasts spanning the fields of video, and media creation

declare @FirstId int = (SELECT min(Id) FROM dbo.Posts WHERE PostTypeId = 1);
DECLARE @FirstQuestion datetime = (SELECT CreationDate FROM dbo.Posts WHERE Id = @FirstId);
DECLARE @LastQuestion datetime = (SELECT MAX(CreationDate) FROM dbo.Posts WHERE PostTypeId = 1);

with AnswerTimes as (
SELECT TagName,
  ISNULL(DATEDIFF(second, q.CreationDate, MIN(a.CreationDate)), 9999999 * 60) TTA
FROM dbo.Posts q
     join PostTags on q.Id = PostId
     join Tags t on t.Id = TagId 
     left JOIN dbo.Posts a ON a.ParentId = q.Id AND a.OwnerUserId <> q.OwnerUserId
WHERE q.PostTypeId = 1 AND q.CreationDate >= @FirstQuestion 
  AND q.ClosedDate IS NULL
  AND q.Score >= 0
  and a.CreationDate > q.CreationDate
  and t.TagName in (##tag##)
GROUP BY q.Id, q.CreationDate, TagName
),
median as (
  select t.TagName, ViewCount,
         -- http://stackoverflow.com/a/8846679/1438
         PERCENTILE_DISC(0.5) 
                  WITHIN GROUP (ORDER BY ViewCount)
                  OVER (PARTITION BY t.TagName)
               median_views,
               
         AnswerCount,
         PERCENTILE_DISC(0.5) 
                  WITHIN GROUP (ORDER BY AnswerCount)
                  OVER (PARTITION BY t.TagName)
               median_answers,
               
         Score,
         PERCENTILE_DISC(0.5) 
                  WITHIN GROUP (ORDER BY Score)
                  OVER (PARTITION BY t.TagName)
               median_score,
         PERCENTILE_DISC(0.5) 
                  WITHIN GROUP (ORDER BY TTA)
                  OVER (PARTITION BY t.TagName)
               median_tta,
         AcceptedAnswerId accepted,
         ClosedDate closed
  from Posts p
       join PostTags on p.Id = PostId
       join Tags t on t.Id = TagId
       join AnswerTimes on t.TagName = AnswerTimes.TagName
  where PostTypeId = 1
        and t.TagName in (##tag##)
)

select TagName, count(*) N, 
       median_views,
       round(avg(1.0*Score), 1) avg_score,
       round(100.0*count(closed)/count(*), 1) closed_rate,
       round(avg(1.0*AnswerCount), 1) avg_answers,
       round(100.0*count(accepted)/count(*), 1) accepted_rate,
       round(100.0*count(case 
                           when AnswerCount > 0 then 1 
                         end)/count(*), 1) answer_rate,
       median_tta

from median m
group by TagName, median_views, median_tta
order by TagName

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results