Recreate a query for the tags associated with a user based on time filter

0

Please login or register to vote for this query.

(click on this box to dismiss)

http://meta.stackexchange.com/questions/252924/recreate-a-query-for-the-tags-associated-with-a-user-based-on-time-filter

Movies and TV Meta

Q&A about the site for movie and tv enthusiasts

with topusers as (
select p.owneruserid
     ,sum(case v.votetypeid when 2 then 
           case p.posttypeid when 1 then 5 else 10 end
           else 0 end) 
       + sum(case v.votetypeid when 3 then -2 else 0 end)
       + sum(case v.votetypeid when 1 then 15 else 0 end) as tot
from posts p 
inner join votes v on v.postid = p.id
where v.creationdate between ##start:string?2015-05-01## 
                         and ##end:string?2015-05-07##
and   v.votetypeid in (1,2,3)
group by p.owneruserid 
)
, toptagsusers as 
(select p.owneruserid as [User Link]
      , t.tagname
      , row_number() over ( partition by p.owneruserid order by
       sum(case v.votetypeid when 2 then 
           case p.posttypeid when 1 then 5 else 10 end
           else 0 end) 
       + sum(case v.votetypeid when 3 then -2 else 0 end)
       + sum(case v.votetypeid when 1 then 15 else 0 end) desc) as rownum
from tags t
inner join posttags pt on pt.tagid = t.id
inner join posts p on pt.postid in (p.id, p.parentid)
inner join votes v on v.postid = p.id
where v.creationdate between ##start:string?2015-05-01## 
                         and ##end:string?2015-05-07##
and   v.votetypeid in (1,2,3)
group by p.owneruserid 
       , t.tagname
)

select top 100 tu.owneruserid as [User Link]
from topusers tu
order by tu.tot desc

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results