Most Viewed Questions Per Day

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

SELECT TOP 20
Questions.Id 
AS [Post Link],
--Questions.Title,
Questions.AnswerCount, 
Questions.ViewCount,
--Questions.FavoriteCount, 
Questions.Score,
AnswerDate,
VoteCount,
Questions.ViewCount/(DateDiff(d, Questions.CreationDate, GetDate())) As ViewsPerDay,
Questions.LastActivityDate--,
--Tags.TagName

FROM Posts AS Answers 
    INNER JOIN Posts AS Questions 
    ON Questions.Id = Answers.ParentId
    
    INNER JOIN Users AS Users
    ON Answers.OwnerUserId = Users.Id
    
    --INNER JOIN PostTags 
    --ON PostTags.PostId = Answers.ParentId
    
    --INNER JOIN Tags
    --ON Tags.Id = PostTags.TagId
    
    LEFT JOIN (select DisplayName, 
  Posts.ParentID,
  Posts.CreationDate as AnswerDate,
  Count(MyVotes.Id) as VoteCount
from Users 
  inner join Posts on Users.Id = Posts.OwnerUserId 
  left join (select * from Votes where VoteTypeId = 2) as MyVotes
              on Posts.Id = MyVotes.PostId
            where Users.Id = 3347858
              and PostTypeId = 2 --1 is Question and 2 is Answer
            group by Users.DisplayName, 
              Posts.ParentID,
              Posts.CreationDate) AS MyAnswers
     ON MyAnswers.ParentId = Questions.Id 

GROUP BY
Questions.Id, 
--Questions.Title,
Questions.AnswerCount, 
Questions.ViewCount,
Questions.CreationDate,
--Questions.FavoriteCount, 
Questions.Score,
Questions.LastActivityDate,
--Tags.TagName,
AnswerDate,
VoteCount

ORDER BY Questions.ViewCount/(DateDiff(d, Questions.CreationDate, GetDate())) DESC

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results