sdwebserver/export_best_laps.sql
Alfonso Saavedra "Son Link e3b5e2d877
Corrected the exporter of best laps per track
The problem was that it was grouping only by car category, and not by track and car category, in this order
2024-12-14 08:55:21 +01:00

36 lines
No EOL
861 B
SQL

DROP TABLE IF EXISTS bests_laps;,
CREATE TABLE `bests_laps` (
`race_id` INT(11) NOT NULL,
`lap_id` INT(11) NOT NULL,
`track_id` VARCHAR(20) NOT NULL,
`car_cat` VARCHAR(100) NOT NULL,
`car_id` VARCHAR(50) NOT NULL,
`laptime` DOUBLE NOT NULL,
`user_id` INT(11) NOT NULL,
`setup` TEXT NULL DEFAULT NULL
)
ENGINE=InnoDB;
INSERT INTO bests_laps
SELECT DISTINCT
r2.id AS race_id,
l.id AS lap_id,
r2.track_id AS track_id,
cc.id AS car_cat,
r2.car_id AS car_id,
l.laptime AS laptime,
r2.user_id AS user_id,
r2.setup AS setup
FROM laps l
INNER JOIN
(
SELECT l3.id, MIN(l3.laptime) AS bestlap
FROM laps l3
JOIN races r ON r.id = l3.race_id
GROUP BY l3.race_id
) l2
ON l2.id = l.id
INNER JOIN races r2 ON r2.id = l.race_id
INNER JOIN cars_cats cc ON cc.carID = r2.car_id
WHERE l2.bestlap = l.laptime
GROUP BY r2.track_id, cc.id