Average Accepted Answer Score by Question Score for Users Like Me

1

Please login or register to vote for this query.

(click on this box to dismiss)

Ask Ubuntu

Q&A for Ubuntu users and developers

DECLARE @Reputation INT
DECLARE @MaxScore INT



SELECT
    @Reputation = Users.Reputation
    
FROM
    Users
    
WHERE
    Users.Id = ##UserId##
    
    

SELECT
    @MaxScore = MAX( Questions.Score ) 

FROM
    Posts AS Questions
    
WHERE
    Questions.OwnerUserId = ##UserId##
    
    

SELECT
    'Everyone' AS UserId,
    Questions.Score AS QuestionScore,
    CAST( AVG( CAST(Answers.Score AS DECIMAL(4,2) ) ) AS DECIMAL(4,2) ) AS AnswerScore,
    CAST( AVG( CAST(Answers.Score AS DECIMAL(4,2) ) ) AS DECIMAL(4,2) ) - Questions.Score AS Difference

FROM
    Posts AS Questions
  
    INNER JOIN
    PostTags
    ON Questions.Id = PostTags.PostId
    
    INNER JOIN
    Tags
    ON PostTags.TagId = Tags.Id
    
    INNER JOIN
    Posts AS Answers
    ON Answers.Id = Questions.AcceptedAnswerId
    
    INNER JOIN
    Users AS AnswerUsers
    ON Answers.OwnerUserId = AnswerUsers.Id
  
WHERE
        Questions.Score BETWEEN 0 and @MaxScore
    AND AnswerUsers.Reputation BETWEEN (@Reputation * .8)
                               AND     (@Reputation * 1.2)
    AND Tags.TagName IN ( 'javascript', 'css', 'html', 'css3', 'html5' )
    
GROUP BY
      Questions.Score
      
      
      
SELECT
    CAST(##UserId## AS CHAR(8)) AS UserId,
    Questions.Score AS QuestionScore,
    CAST( AVG( CAST(Answers.Score AS DECIMAL(4,2) ) ) AS DECIMAL(4,2) ) AS AnswerScore,
    CAST( AVG( CAST(Answers.Score AS DECIMAL(4,2) ) ) AS DECIMAL(4,2) ) - Questions.Score AS Difference

FROM
    Posts AS Questions
  
    INNER JOIN
    PostTags
    ON Questions.Id = PostTags.PostId
    
    INNER JOIN
    Tags
    ON PostTags.TagId = Tags.Id
    
    INNER JOIN
    Posts AS Answers
    ON Answers.Id = Questions.AcceptedAnswerId
  
WHERE
        Tags.TagName IN ( 'javascript', 'css', 'html', 'css3', 'html5' )
    AND Answers.OwnerUserId = ##UserId##
    
GROUP BY
    Questions.Score

Enter Parameters

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