Q&A about the site for administrators and users of the CiviCRM Constituent Relationship Management software
/*select top 100 * from VoteTypes; select top 100 * from Votes where PostId = 356123; select cont(v.Id), v.PostId, vt.Name from Votes v, VoteType vt where v.VoteTypeId = vt.Id and vt.Name in ('UpMode','DownMode')*/ with rankedupvotes as ( select v.postid, vt.name, count(v.id) as votecount, row_number() over (order by count(v.id) desc) as rownum from votes v join votetypes vt on v.votetypeid = vt.id where vt.name = 'UpMode' group by v.postid, vt.name ), rankeddownvotes as ( select v.postid, vt.name, count(v.id) as votecount, row_number() over (order by count(v.id) desc) as rownum from votes v join votetypes vt on v.votetypeid = vt.id where vt.name = 'DownMode' group by v.postid, vt.name ) select postid, name, votecount from rankedupvotes where rownum <= 10 union all select postid, name, votecount from rankeddownvotes where rownum <= 10;