Postgres

0

Please login or register to vote for this query.

(click on this box to dismiss)

select * from Users u join (select top 10 a.OwnerUserId as Id, count(a.OwnerUserId) as TrueAnswer from (select * from Posts where PostTypeId=2) a join (select * from Posts where PostTypeId=1) q on a.Id=q.AcceptedAnswerId group by a.OwnerUserId order by TrueAnswer desc) s on u.Id=s.Id order by s.TrueAnswer desc;

Motor Vehicle Maintenance and Repair Meta

Q&A about the site for mechanics and DIY enthusiast owners of cars, trucks, and motorcycles

select top 50000 * 
into #LPosts
from Posts;

with s(Id, WinRate, TrueAnswer, Answer) as(
select s1.Id as Id, (cast(s1.TrueAnswer as float)/s2.Answer * 100) as WinRate, 
            s1.TrueAnswer as TrueAnswer, s2.Answer as Answer
            from(select a.OwnerUserId as Id, count(a.OwnerUserId) as TrueAnswer
                from (select * from #LPosts where PostTypeId=2) a inner join 
                    (select * from #LPosts where PostTypeId=1) q 
                  on  a.Id=q.AcceptedAnswerId
                group by a.OwnerUserId) s1
              inner join
                (select OwnerUserId as Id, count(OwnerUserId) as Answer
                from  #LPosts
                where PostTypeId=2
                group by OwnerUserId
                having count(OwnerUserId)>20) s2
              on s1.Id=s2.Id)


select *
from Users u inner join
    (select *
    from s
    where WinRate=(select MAX(WinRate) from s)
    )s
on u.Id=s.Id;

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results