私はこれでボールの転がりを得るでしょう...しかし、より効率的なオプションが用意されてい...
DROP TABLE IF EXISTS my_table;
CREATE TABLE my_table
(race_id INT NOT NULL
,participant_id INT NOT NULL
,time DECIMAL (5,2) NOT NULL
,PRIMARY KEY(race_id,participant_id)
);
INSERT INTO my_table VALUES
(1,15,1.0),
(1,21,1.05),
(1,27,2),
(2,27,2.55),
(2,15,2.75),
(2,21,3.45);
SELECT x.*
, MIN(y.time - x.time) delta
FROM my_table x
JOIN my_table y
ON y.race_id = x.race_id
AND y.time > x.time
JOIN
(SELECT race_id
, MIN(time) time
FROM my_table
GROUP
BY race_id
) z
ON z.race_id = x.race_id
AND z.time = x.time
GROUP
BY race_id
, participant_id
, time;
+---------+----------------+------+-------+
| race_id | participant_id | time | delta |
+---------+----------------+------+-------+
| 1 | 15 | 1.00 | 0.05 |
| 2 | 27 | 2.55 | 0.20 |
+---------+----------------+------+-------+