mysql - DB, how to select data based on time and particular interval -


i have table in database, program insert data table in every 10 mins.

the table has field recording insert date , time.

now want retrieve data, don't want hundreds of data comes out.

i want 1 records every half hour based on insert time stamp (so less 50 in total of day).

for 1 record, can either random pick or average each interval. sorry ambiguit, cuz wanna figure out way select intervals

let say,

table name: network_speed   ----------------------------------  id.  .......  speed   .........     insert_time  1    .......    10    .........         10:02am...... 2    .......    12    .........         10:12am...... ... ... ... 123   .......   17     ........        9:23am........ 

to them out put must average of each half hour record

how can write query achieve this?

here query calculates half hour intervals on specific day ( 2013-09-04).

select id, speed, insert_time, round(timestampdiff(minute, '2013-09-04', insert_time)/48) 'interval' network_speed date(insert_time) = '2013-09-04'; 

use in nested query stats on records in intervals.

select it.interval, count(id), min(insert_time), max(insert_time), avg(speed)     (select id, speed, insert_time,      round(timestampdiff(minute, '2013-09-04', insert_time)/48) 'interval'      network_speed      date(insert_time) = '2013-09-04') group it.interval; 

here used first record in each interval.

select ns.*     (select it.interval, min(id) 'first_id'              (select id, speed, insert_time,          round(timestampdiff(minute, '2013-09-04', insert_time)/48) 'interval'          network_speed          date(insert_time) = '2013-09-04')      group it.interval) mi,      network_speed ns mi.first_id = ns.id; 

hope helps.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -