我有一个包含3列的表
ID | Teamid | Timestamp
我们知道由参与者驱动的一轮是2KM,每次他们通过控制点时都会添加一个时间戳
现在我们正在搜索所选团队计算每个时间戳之间的平均速度,以便我们将其放在折线图上。
ID | Ploegnr| Tijdstamp
----------------------------------------
1 | 1 | 2013-06-28 18:35:28
2 | 1 | 2013-06-28 18:36:28
3 | 2 | 2013-06-28 18:36:30
4 | 3 | 2013-06-28 18:37:28
5 | 2 | 2013-06-28 18:40:28
6 | 1 | 2013-06-28 18:42:28
8 | 3 | 2013-06-28 18:48:28
让某人知道或了解如何开始
这是另一个查询,它取最近2个时间戳的平均值
我已查询过去2个时间戳
SELECT a.*
, 3600 / (UNIX_TIMESTAMP(a.Tijdstamp) - UNIX_TIMESTAMP(b.Tijdstamp)) * 2 snelheid
FROM
( SELECT x.*
FROM Ronde x
JOIN Ronde y
ON y.Ploegnr = x.Ploegnr
AND y.Tijdstamp >= x.Tijdstamp
GROUP
BY x.ID
HAVING COUNT(*) = 1
) a
JOIN
( SELECT x.*
, COUNT(*) rank
FROM Ronde x
JOIN Ronde y
ON y.Ploegnr = x.Ploegnr
AND y.Tijdstamp >= x.Tijdstamp
GROUP
BY x.ID
HAVING COUNT(*) = 2
) b
ON b.Ploegnr = a.Ploegnr
left join Ploeg as l on l.id = b.ploegnr ;