Question stats by tag

4

Please login or register to vote for this query.

(click on this box to dismiss)

Science Fiction and Fantasy

Q&A for science fiction and fantasy enthusiasts

with 

answers as (
  SELECT q.PostTypeId PostTypeId,
         ISNULL(DATEDIFF(second, q.CreationDate, MIN(a.CreationDate)), 
                9999999 * 60) TTA

  FROM dbo.Posts q
       left JOIN dbo.Posts a ON a.ParentId = q.Id 
                                AND a.OwnerUserId <> q.OwnerUserId
  WHERE q.PostTypeId = 1
        AND q.ClosedDate IS NULL
        AND q.Score >= 0
        and a.CreationDate > q.CreationDate
  GROUP BY q.Id, q.PostTypeId, q.CreationDate
),

median_answer as (
  select PERCENTILE_DISC(0.5) 
                  WITHIN GROUP (ORDER BY TTA)
                  OVER (PARTITION BY PostTypeId)
               median_tta
  from answers
),

medians as (
  select TagName, 
         -- http://stackoverflow.com/a/8846679/1438
         PERCENTILE_DISC(0.5) 
                  WITHIN GROUP (ORDER BY ViewCount)
                  OVER (PARTITION BY TagName)
               median_views,
               
         PERCENTILE_DISC(0.5) 
                  WITHIN GROUP (ORDER BY AnswerCount)
                  OVER (PARTITION BY TagName)
               median_answers,
               
         PERCENTILE_DISC(0.5) 
                  WITHIN GROUP (ORDER BY Score)
                  OVER (PARTITION BY TagName)
               median_score
  from Posts p
       join PostTags on p.Id = PostId
       join Tags t on t.Id = TagId
  where PostTypeId = 1
        and TagName in (##tag##)
),

counts as (
  select TagName, ViewCount,
         AnswerCount,
         Score,
         AcceptedAnswerId accepted,
         ClosedDate closed
  from Posts p
       join PostTags on p.Id = PostId
       join Tags t on t.Id = TagId
  where PostTypeId = 1
        and TagName in (##tag##)
)

select m.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

from medians m
     join counts c on c.TagName = m.TagName
group by m.TagName, median_views
order by m.TagName

Enter Parameters

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