1st task

0

Please login or register to vote for this query.

(click on this box to dismiss)

CiviCRM Meta

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 top 10
        v.postid,
        vt.name,
        count(v.id) as votecount
    from votes v
    join votetypes vt on v.votetypeid = vt.id
    where vt.name = 'UpMode'
    group by v.postid, vt.name
    order by count(v.id) desc
),
rankeddownvotes as (
    select top 10
        v.postid,
        vt.name,
        count(v.id) as votecount
    from votes v
    join votetypes vt on v.votetypeid = vt.id
    where vt.name = 'DownMode'
    group by v.postid, vt.name
    order by count(v.id) desc
)
select postid, name, votecount
from rankedupvotes

union all

select postid, name, votecount
from rankeddownvotes;

Enter Parameters

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