Ok I don't know what I'm doing 
I'm a telecom guy that knows a little bit of SQL, enough to troubleshoot my systems and talk with DBA folk about stuff I need. But I need a query that I can't figure out. Wondering if anyone can help me out.
Here is the table
And I need a query that pulls something like so:
I'm ok running 24 queries (1 for each hour) if I have too. Here is the part that is tricky for me. If a call spans an hour, for instance the first call. The time needs to be slit up between the hours that it is in. So for this call 8 minutes or 480 seconds falls into the 6:00am-6:59am category.
To me this seems pretty simple from a programming standpoint. If I had to parse the data via C++, VB or perl this would be simple cause I could do conditional statements and loops and such. I just can't seem to figure out how to do it with SQL.
Any ideas/help/things I can plagerize
I'm a telecom guy that knows a little bit of SQL, enough to troubleshoot my systems and talk with DBA folk about stuff I need. But I need a query that I can't figure out. Wondering if anyone can help me out.
Here is the table
Code:
TableName: call_detail
ORIG_GROUP ORIG_TIME TERM_TIME
1 65200 72500
1 65800 65900
1 72000 72100
1 72304 72335
1 72421 72431
3 62500 63200
3 64000 84000
And I need a query that pulls something like so:
Code:
Hour Group Total Duration In Seconds
6:00am-6:59am 1 540
3 1620
7:00am-7:59am 1 1601
3 3600
8:00am-8:59am 3 2400
To me this seems pretty simple from a programming standpoint. If I had to parse the data via C++, VB or perl this would be simple cause I could do conditional statements and loops and such. I just can't seem to figure out how to do it with SQL.
Any ideas/help/things I can plagerize