mysql - Group datetime within range -


i have troubles in grouping datasets. here query , query result.

select count(*),salarie_id, created_at enregistrement  group salarie_id, created_at 

my point group similar created_at rows, in interval of +/- 3 sec. didn't manage it, in using interval, in such criterias having , where ... between.

how can group these rows get, example 36 (33+3) in count result, shown in image ?

didn't found suitable solution... let me know if want additional information.


update 1 : looks @fancypants solution on right way.

select count(*),salarie_id, date_format(created_at, concat('%y-%m-%d %h:%i:', left(right(created_at, 2), 1), right(created_at, 1) % 3)) 'date' enregistrement  group salarie_id, date_format(created_at, concat('%y-%m-%d %h:%i:', left(right(created_at, 2), 1), right(created_at, 1) % 3)) 

select count(*),salarie_id, created_at enregistrement  group salarie_id,  date_format(created_at, concat('%y-%m-%d %h:%i:', left(right(created_at, 2), 1),  case when right(created_at, 1) between 1 , 4 0 when right(created_at, 1) between 5 , 7 1 else 2 end )); 

you can use date_format() bring datetime/timestamp column in shapes. in case specify format with

concat('%y-%m-%d %h:%i:', left(right(created_at, 2), 1), right(created_at, 1) % 3)) 

is, take year, month, day, hour, minute. concatenate date format string power of ten of seconds.

for example have seconds:

21 33 36 40 

then take 2, 3, 3 , 4 left(right(created_at, 2), 1). 1, 3, 6 , 0 right(created_at, 1). have put them self-defined groups case when.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -