5

How can I use the data explorer to fetch the top viewed questions within a certain tag within some time frame on Stack Overflow?

For example, the top viewed questions tagged [Android] in the last 6 months.

Here is a query that fetches top viewed questions by tag, but still, need some help.

Update

@Arulkumar answer is helpful but it does not fulfill the need. His answer fetches questions asked in that time frame.

But I want to get most viewed questions within the time frame with a certain tag.

  • 1
    Which site? SEDE generally needs to be separated by site. Several sites have questions about Android. Heck, there's an entire site about it, Android Enthusiasts. – Catija Aug 17 '18 at 13:13
  • In Stackoverflow – Khemraj Aug 17 '18 at 13:14
2

You can add the Period in months as integer and handle with DATEADD in the WHERE clause as (Q.CreationDate BETWEEN DATEADD(MONTH, -@Period, GETUTCDATE()) AND GETUTCDATE()).

Query in SEDE

DECLARE @Tag VARCHAR(35) = '##Tag##'
DECLARE @Period INT = '##Period##'

SELECT TOP 50 Q.Id AS [Post Link], 
    Q.Tags, Q.AnswerCount, Q.ViewCount
FROM Posts AS Q
INNER JOIN PostTags AS P ON P.PostId = Q.Id
INNER JOIN Tags AS T ON T.Id = P.TagId
WHERE T.TagName = @Tag AND
      (Q.CreationDate BETWEEN DATEADD(MONTH, -@Period, GETUTCDATE()) AND GETUTCDATE())
ORDER BY Q.ViewCount DESC
  • It is gonna be my favorite query :), thank you so much. – Khemraj Aug 17 '18 at 13:34
  • How can I save query to my favorites? – Khemraj Aug 17 '18 at 13:35
  • Once you login the data.stackexchange.com, you can easily favorite this query to your account – Arulkumar Aug 17 '18 at 14:15
  • 1
    Note that tagnames can now be up to 35 chars – rene Aug 17 '18 at 20:12
  • Hi, today I noticed this query is showing only questions asked from time frame I entered. But my need is to fetch from all questions on stackoverflow. – Khemraj Sep 6 '18 at 11:40
  • @Khemraj That was your requirement the top viewed questions tagged [android] in the last 6 months.. If you are need to find irrespective of the time frame, remove the date range check from the WHERE clause in the query – Arulkumar Sep 6 '18 at 12:35
  • Your answer is very useful for me, but my need was questions that were viewed the most in last 6 months. You got me bro? You also filtered questions asked in last 6 month. – Khemraj Sep 6 '18 at 12:37
  • 2
    @Khemraj that data isn't in the public SEDE instance. The history of viewcount isn't available. – rene Sep 6 '18 at 19:15
  • Okay @rene , thanks for your time. I was just wondering to see the topics trending on Stackoverflow. – Khemraj Sep 6 '18 at 19:46

You must log in to answer this question.

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