SELECT pa.Mentions##Keyword## , count(distinct pp....

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

SELECT  pa.Mentions##Keyword##
,       count(distinct pp.id) as PostCount
,       SUM(case when v.votetypeid = 1 then 15
                 when v.votetypeid = 2 then 10
                 when v.votetypeid = 3 then -2
                 else null 
            end) / COUNT(distinct pp.id) AS RepGain
FROM    tags t
JOIN    posttags pt
ON      pt.tagid = t.id
JOIN    posts pp
ON      pp.id = pt.postid
JOIN    (
        select  *
        ,       case when body like '%##Keyword##%' then 1 
                     else 0 
                end as Mentions##Keyword##
        from    posts
        ) pa
ON      pa.parentid = pp.id
JOIN    votes v
ON      v.postid = pa.id
WHERE   t.tagname = '##TagName##'
GROUP BY 
        pa.Mentions##Keyword##

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached