Finding maximum number of votes to a person per state

0

Please login or register to vote for this query.

(click on this box to dismiss)

http://stackoverflow.com/questions/5771240/finding-maximum-number-of-votes-to-a-person-per-state

Stack Overflow

Q&A for professional and enthusiast programmers

-- Enter Query Title
-- Enter Query Description




declare @votes table (vid int, stateid int, voterid int, voteeid int)
insert @votes values
 (1,         1,           1,           1),
 (2,         1,           2,           1),
 (3,         1,           3,           1),
 (4,         1,           4,           1),
 (5,         1,           5,           2),
 (6,         1,           6,           2),
 (7,         2,           7,           3),
 (8,         2,           8,           3),
 (9,         2,           9,           4);
 
select  stateid
,    voteeid
,    votes
from    (
        select  stateid
        ,       voteeid
        ,       count(*) as votes
        ,       row_number() over (partition by stateid order by count(*) desc) as rn
        from    @votes
        group by
                stateid
        ,       voteeid
        ) cnt
where   rn = 1

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results