Reputation: 53
I have a table like
datetime game sum Releated
01/03/2015 00:00:25 Game1 1342.75
01/03/2015 00:01:52 Game2 1418.5
01/03/2015 00:01:53 Game3 1289
01/03/2015 00:04:41 Game4 1473.25
01/03/2015 00:06:09 Game5 1581.25
to become something like this.
datetime game sum Releated
01/03/2015 00:00:25 Game1 1342.75
01/03/2015 00:01:52 Game2 1418.5 01/03/2015 00:01:52
01/03/2015 00:01:53 Game3 1289 01/03/2015 00:01:52
01/03/2015 00:04:41 Game4 1473.25
01/03/2015 00:06:09 Game5 1581.25
If two or more rows are within 10 seconds time difference (e.g: 2nd and 3rd row) I want to update related columns to mark it. Either with datetime
or some value. Which mean that are the same row set.
or
Based on the same theory I want to sum the sum column if they are between 10 seconds range.
Upvotes: 2
Views: 177
Reputation: 16958
Try this:
SELECT *,
(SELECT min(t2.d)
FROM yourTable t2
WHERE ABS(TIMESTAMPDIFF(SECOND,t2.d, t1.d)) <= 10
AND t2.d <> t1.d
) As related
FROM yourTable t1;
Upvotes: 1
Reputation: 6253
SELECT * FROM harronLati a inner join harronLati b
WHERE
ABS(TIMESTAMPDIFF(SECOND,a.datetime,b.datetime)) <= 10
group by a.datetime,a.game,a.sum,a.Releated
Upvotes: 0