I need to get the fastest players who reach certain milestone with minimum total games in the following simplified table:
create table eg(
kills integer,
matchid integer,
playername varchar(30)
date date
)
INSERT INTO eg (kills,matchid,playername,date) values(12,1,'niko','2015-01-01');
INSERT INTO eg (kills,matchid,playername,date) values(13,2,'niko','2015-01-02');
INSERT INTO eg (kills,matchid,playername,date) values(5,3,'device','2015-01-03');
INSERT INTO eg (kills,matchid,playername,date) values(6,4,'niko','2015-01-04');
INSERT INTO eg (kills,matchid,playername,date) values(5,5,'device','2015-01-05');
INSERT INTO eg (kills,matchid,playername,date) values(5,3,'device','2015-01-06');
INSERT INTO eg (kills,matchid,playername,date) values(5,3,'device','2015-01-07');
but it caused duplicate.
The query i used is as followed:
select distinct(playername),sum_value,game_played
from(
select playername,
sum(kills) over (partition by playername order by date asc, matchid asc) as sum_value,
count(*) over (partition by playername order by date asc, matchid asc) as game_played
from eg) as so
where sum_value>15
order by game_played asc
the result I ideally want is the below
playname sum_value game_played
niko 25 2
device 20 4
but what i got is:
playname sum_value game_played
niko 25 2
niko 31 3
device 20 4
So I would prefer a modification to the query that removes dublicate names and only give me the first instance of the player name.
can someone help me with this? Thanks