select top 20 v.*, p.Id [Post Link] from Posts p inner join

0

Please login or register to vote for this query.

(click on this box to dismiss)

Motor Vehicle Maintenance and Repair Meta

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

select top 20
    v.*,
    p.Id [Post Link]
from
    Posts p
inner join
  (
    select
        PostId,
        sum(case when VoteTypeId = 2 then 1 else 0 end) up,
        sum(case when VoteTypeId = 3 then 1 else 0 end) down
    from
        Votes
    group by
        PostId
  ) v
  on
    p.Id = v.PostId
where
    OwnerUserId = 396458
order by
    down desc,
    up desc,
    id asc

-- Enter Query Title

Enter Parameters

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