mysql - SQL group by using distinct column -
i collecting lap times in sql database , having difficulties extracting drivers fastest laptimes!
the structure looks following!
create table if not exists `leaderboard` ( `id` int(11) not null auto_increment, `driver` varchar(50) not null, `car` varchar(50) not null, `best` double not null, `guid` bigint(255) not null, `server_name` varchar(255) not null, `track` varchar(55) not null, primary key (`id`), key `driver` (`driver`), key `server_name` (`server_name`) ) engine=innodb default charset=latin1 auto_increment=1213 ;
data example
insert `leaderboard` (`id`, `driver`, `car`, `best`, `guid`, `server_name`, `track`) values (1, 'dave.38', 'bmw_m3_e30', 88.379, 76561198084629688, 'a++%21+a++%21+------+saturdaynightracing.tk+-+%5brace-server%5d+-+%5bmagione%5d+%23snr', 'magione'), (2, 'gabriel porfÃrio', 'bmw_m3_e30', 87.318, 76561197987062834, 'a++%21+a++%21+------+saturdaynightracing.tk+-+%5brace-server%5d+-+%5bmagione%5d+%23snr', 'magione'), (3, 'xx_vega_xx', 'bmw_m3_e30', 88.23, 76561198182074333, 'a++%21+a++%21+------+saturdaynightracing.tk+-+%5brace-server%5d+-+%5bmagione%5d+%23snr', 'magione'), (4, 'dave.38', 'bmw_m3_e30', 88.379, 76561198084629688, 'a++%21+a++%21+------+saturdaynightracing.tk+-+%5brace-server%5d+-+%5bmagione%5d+%23snr', 'magione'), (5, 'gabriel porfÃrio', 'bmw_m3_e30', 87.318, 76561197987062834, 'a++%21+a++%21+------+saturdaynightracing.tk+-+%5brace-server%5d+-+%5bmagione%5d+%23snr', 'magione');
now trying sort out drivers best time using column best
using following sql appears if times discarded, combination of sort , order not work.
select distinct guid, car, best, driver `leaderboard` `server_name` '%%' , `track` = 'magione' group by(driver) order `best` * 1 limit 10
please driving me mad!
some fields in data not clear, made such assumptions:
guid
means driver's guid (because same same driver in data).car
same same driver.
with these assumptions can use simple group by
results need:
select driver, car, min(best) best_time, guid leaderboard `server_name` '%%' , `track` = 'magione' group driver, car, guid order min(best)
Comments
Post a Comment