Question : Query to select based on time

Greetings,

My table has three colums ID,call_start,duration

ID    Call_start                        Duration
1     2010-07-04 00:01:10        5
1     2010-07-04 00:05:12        6
1     2010-07-04 00:10:56        9
2     2010-07-04 00:15:33       10
2     2010-07-04 00:25:13       11
2     2010-07-04 00:30:16       12
1     2010-07-04 01:15:15        9
1     2010-07-04 01:20:09        8
1     2010-07-04 01:25:08       12
2     2010-07-04 01:30:09        7
2     2010-07-04 01:40:09        6
2     2010-07-04 01:50:11        3

Like this I have many records with many id's.Now I need to know the average duration per ID per hour say for eg average duration for ID 1  from 00:00:00  to 00:59:59 is 20/3 =6.66.
Please let me know a simple mysql query to do that.

Regards,
 
Related Solutions: Joining 3 tables

Answer : Query to select based on time

select ID, date(call_start) as date_call, hour(call_start) as hour_call,
 concat(floor(avg(1.0*duration)/60),':',round(avg(1.0*duration)%60)) as avg_duration_mm_ss_string
from tbl
group by ID, date(call_start), hour(call_start)
order by 1,2,3

It's actually 6:44 since .74 of a minute is 44.4 seconds.
Random Solutions  
 
programming4us programming4us