postgresql - PostgresSql how to GROUP BY multiple columns and get all other columns aswell? -
i want group 3 columns , data columns.
this worked, don't data lap.valid, lap."timestamp" , lap.maxspeed_kmh:
select players.name, cars.car, tracks.track, min(lap.laptime) best_laptime lap join playerinsession on lap.playerinsessionid = playerinsession.playerinsessionid join session on playerinsession.sessionid = session.sessionid join tracks on session.trackid = tracks.trackid join cars on playerinsession.carid = cars.carid join players on playerinsession.playerid = players.playerid group players.name, cars.car, tracks.track;
this want do:
select players.name, cars.car, tracks.track, min(lap.laptime) best_laptime, lap.valid, lap."timestamp", lap.maxspeed_kmh lap join playerinsession on lap.playerinsessionid = playerinsession.playerinsessionid join session on playerinsession.sessionid = session.sessionid join tracks on session.trackid = tracks.trackid join cars on playerinsession.carid = cars.carid join players on playerinsession.playerid = players.playerid group players.name, cars.car, tracks.track;
but error "column lap.valid must appear in group ...", how fix this?
the important thing fastest lap time each player each car , track combo. there hundreds of lap times each track done multiple players in different cars.
check distinct on
select distinct on (p.name, c.car, t.track) p.name, c.car, t.track, l.laptime best_laptime, l.valid, l."timestamp", l.maxspeed_kmh lap l join playerinsession on l.playerinsessionid = playerinsession.playerinsessionid join session on playerinsession.sessionid = session.sessionid join tracks t on session.trackid = t.trackid join cars c on playerinsession.carid = c.carid join players p on playerinsession.playerid = p.playerid order p.name, c.car, t.track, l.laptime
Comments
Post a Comment