Group items with a date difference of 10 minutes between you

Asked

Viewed 259 times

5

I have a table called tb_log, in it I have some data id, usuario_id, produto_id,..., data.

I need to group the records by date as follows: All records that differ by up to 10 minutes from each other.

That is, if the first and the second have a difference of 10 minutes, group, if the third has difference of 10 minutes with the first or the second, enters the same grouping.

  • Which BDS are you using? 2º The first minute would start with 0? 3º The grouping for 10 minutes would be to later do a sum or count of the records?

  • Have any answers solved what was in doubt? Do you need something else to be improved? Do you think it is possible to accept it now?

  • The answer helped you?

1 answer

0

Here I am considering that your field data is TIMESTAMP:

SELECT
    data, 
    usuario_id,
    count(usuario_id)
FROM tb_log 
WHERE …
GROUP BY 
UNIX_TIMESTAMP(data) DIV 600, usuario_id

Browser other questions tagged

You are not signed in. Login or sign up in order to post.