I need to calculate the average time of all the operations stored in the database. The table I store operations in looks as follows:
creation time | operation_type | operation_id
2017-01-03 11:14:25 | START | 1
2017-01-03 11:14:26 | START | 2
2017-01-03 11:14:28 | END | 2
2017-01-03 11:14:30 | END | 1
In this case operation 1 took 5 seconds and operation 2 took 2 seconds to finish.
How can I calculate the average of these operations in MySQL?
EDIT: It seems that operation_id doesn't need to be unique - given operation may be executed several times, so the table might look as follows:
creation time | operation_type | operation_id
2017-01-03 11:14:25 | START | 1
2017-01-03 11:14:26 | START | 2
2017-01-03 11:14:28 | END | 2
2017-01-03 11:14:30 | END | 1
2017-01-03 11:15:00 | START | 1
2017-01-03 11:15:10 | END | 1
What should I add in the query to properly calculate the average time of all these operations?