5

I want to find out the tag usage over time, across all tags.

As my first step I wrote the following query to give me the tag usage for "sql" over time.

SELECT --TOP 20 
    convert(varchar, CreationDate, 101),
    COUNT(*) AS questions
 FROM Tags
    INNER JOIN PostTags ON PostTags.TagId = Tags.id
    INNER JOIN Posts ON Posts.ParentId = PostTags.PostId
WHERE 
    Tags.tagname = 'sql'
GROUP BY convert(varchar, CreationDate, 101) 
ORDER BY convert(varchar, CreationDate, 101) ASC    

Questions:

3

1 Answer 1

1

It is a way to get the usage per day. I wouldn't convert to a varchar but to a date because that enable SEDE to create a graph, which was also mentioned by Daniel.

My attempt can be found here

SELECT 
    dateadd(m, -datediff(m, CreationDate, getdate()),getdate()),
    COUNT(*) AS questions
 FROM Tags
    INNER JOIN PostTags ON PostTags.TagId = Tags.id
    INNER JOIN Posts ON Posts.Id = PostTags.PostId
WHERE 
    Tags.tagname = 'sql'
GROUP BY  dateadd(m, -datediff(m, CreationDate, getdate()),getdate())
ORDER BY  dateadd(m, -datediff(m, CreationDate, getdate()),getdate()) ASC    

Notice how I used date calculations and reduced the clutter to counts per month.

One very significant change I made is in the join. You joined on post.parentid and that basically joined all answer posts for a question. But only questions have tags so you better join the posts.id instead.

You can find the explanation of the SEDE schema in: Database schema documentation for the public data dump and SEDE over on MSE.

On MSE you also find a couple of common/starter queries to show the possibilities of SEDE, like this one and this one

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .