I am trying to replicate the top user page with userthe users sorted by number of postposts.
Suppose there are two users .:
User 'A' with 5608 post (Answers + questions) And User 'B' with 2627 post(Answers + question). QueryThe query results should be:
List
User A
User B
So far I have written querya query to list the top 100 users withwith the most postposts ( answersanswers and questions)
. The query is below:
Select Top 100
OwnerUserId as [User Link]
, sum(score) score
, count(*) [# posts]
, sum(case posttypeid when 1 then score else 0 end) [question score]
, sum(case posttypeid when 2 then score else 0 end) [answer score]
, sum(case posttypeid when 1 then 1 else 0 end) [# questions]
, sum(case posttypeid when 2 then 1 else 0 end) [# answers]
from Posts p
inner join posttags pt on pt.postid = coalesce(p.parentid, p.id)
WHERE
owneruserid is not null
and posttypeid in (1,2) -- only questions and answers
and communityowneddate is null
group by owneruserid
order by sum(score) desc
This query is sorting results incorrectly. It It shows:
2. BalusC (Post 17035 post)
3. Darin Dimitrov (post 21486)
The one with more postposts is at the third rank. I I could not figure out what is wrong?
But I, and could not write a correct query for it?.
I have referedreferred to these postposts: