M
M
MhMadHamster2014-10-28 21:09:20
MySQL
MhMadHamster, 2014-10-28 21:09:20

How to correctly compose a complex MySQL query with grouping records according to certain criteria?

Actually there is a table of the form:
calls(src, dst, start, end) and some more non-significant fields the
table is filled as follows:
src dst | start | end
1 | 2 | 1970-01-01 10:00:00 | 1970-01-01 10:05:35
1 | 3 | 1970-01-01 10:00:00 | 1970-01-01 10:03:13
1 | 1 | 1970-01-01 10:03:13 | 1970-01-01 10:05:37
2 | 5 | 1970-01-01 10:03:20 | 1970-01-01 10:04:01
1 | 3 | 1970-01-01 10:07:15 | 1970-01-01 10:08:29
respectively src number from which they call, dst extension number they call,
the task is to get the number of real calls, that is, all records within the same start - end interval for one incoming number must be combined into one, for example, for the table above, the query should output:
src | dst | start | end
1 | 2 | 1970-01-01 10:00:00 | 1970-01-01 10:05:37
2 | 5 | 1970-01-01 10:03:20 | 1970-01-01 10:04:01
1 | 3 | 1970-01-01 10:07:15 | 1970-01-01 10:08:29
in the original table for a new call, the first entry goes with the beginning and end of the call, while the end of the call covers all "transfers" of this number to other extensions, while the end of the last conversation with this number for this call may have an error of +10 seconds, as in the example
, I assume that it is necessary to use grouping with conditions, but it is not entirely clear how to combine into one record, records with the same source number and time interval within the start-end, if neither start nor end match the values ​​of the the first record for this call, besides, the same number may call later and it will already be another call, perhaps it is better to divide the entire task into more specific requests and work with them already in php, what can you tell?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Entelis, 2014-10-28
@DmitriyEntelis

That is, you want to say that in this example you called at 10:00 to number 2,
instantly ?!?? it was redirected to number 3, at 10:03:13 it was redirected to number 1, and at 10:05:37 the conversation ended, and the first entry contains an erroneous value?
I would pull it into PHP and rake it there, the script seems to be not very complicated, it should turn out in O (N)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question