Tags crossings

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

-- The graph shows the ranking of the current top @topn tags matching @Tag 
-- starting @goBackMonths months ago
-- This way one can clearly see when two tags crossed (i.e. switched rank)
-- An alternative to the "bar chart race" visualization


DECLARE @goBackMonths int
SET @goBackMonths = ##goBackMonths:int?72##

create table #tags (Date date, TagName nvarchar (35), Count int);

insert into #tags 

select 
dateadd(month, datediff(month, 0, p.CreationDate), 0) as [Date], t.TagName,
count(*) as Count
from Posts p
join PostTags pt on pt.PostId = p.Id
join Tags t on t.Id = pt.TagId 
where 
DATEDIFF(month,p.CreationDate,getdate()) <= @goBackMonths
AND
(t.TagName like ##Tag:string?%##)
group by t.TagName,
         dateadd(month, datediff(month, 0, p.CreationDate), 0)
order by [Date] desc;


select [Date],TagName,
RANK() OVER   
    (PARTITION BY [Date] ORDER BY Count ASC) AS Rank
from #tags 
where 
DATEDIFF(month,Date,getdate()) in (@goBackMonths, 2)
AND TagName in
(
select TOP ##topn:int?5## TagName from #tags 
where 
DATEDIFF(month,Date,getdate()) =1
order by Count desc
)
order by [Date] asc;

Enter Parameters

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