Q&A about the site for administrators, end users, developers and designers for Craft CMS
select p.id, count(v.id), 'upvote'
from posts p
left join votes v on p.id = v.postid
left join votetypes t on v.votetypeid = t.id and t.name = 'upvote'
where 1 = 1
--and p.id <= 10000
group by p.id
order by count(v.id) desc;