I need to find highest voters in each year Oracle SQL query -


i have 1 table lets ranking info has

username   mvid  votedate john        1    23-sep-90 john        2    23-sep-90 smith       1    23-sep-90 john        3    24-oct-91 smith       3    24-oct-91 smith       4    25-dec-91 smith       5    25-dec-91 

i need write sql query in sqldeveloper(oracle) give me member has given largest number of votes in each year. output should username,year, total number of votes in each year. lets consider above example: need output this.

username  year  number_of_votes john       1990    2 smith      1991    3 

because in 1990 john beat smith 1 vote while in 1991 smith beat john 2 votes.

i point counted votes not maximum number of votes in year.

this have done:

select r1.username,      extract(year r1.votedate)"year",     count(username) rankinginfo r1 extract(year r1.votedate)  not null group extract(year r1.votedate),        r1.username; order  extract(year r1.votedate),       username; 

select  *    (         select  votesperuserperyear.*         ,       dense_rank() on (                     partition voteyear                     order votecount desc) rn            (                 select  username                 ,       extract(year votedate) voteyear                 ,       count(*) votecount                    yourtable                 group                         username                 ,       extract(year votedate)                 ) votesperuserperyear         ) subquerywithrank   rn = 1 -- top voter per year 

example @ sql fiddle.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -