F
F
freelion932019-09-16 11:02:48
MySQL
freelion93, 2019-09-16 11:02:48

How to calculate the average difference between values ​​in SQL?

The structure of the table is as follows:
5d7f3d60f1de3726263518.jpeg
It is required to find the average difference between actions in time (timestamp) for each object (file).
For example File1 had 4 activities:
Activity1 at time 1549256689
Activity2 at time 1549655521
Activity3 at time 1550165431
Activity4 at time 1550317858
For example File2 had 2 activities:
Activity1 at time 1548548573
Activity2 at time
1549875732 File2 1327159, total average 973436
How to write a SQL query to find such an average difference?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freelion93, 2019-09-16
@freelion93

I got a pretty top answer from Stack Overflow, the guys there understood everything without linking to references and sending to a simple avg function, the following came out:
Thanks to everyone who tried to help!
PS in the eighth version there is still a LEAD statement for iterations

B
Boris Korobkov, 2019-09-16
@BorisKorobkov

https://dev.mysql.com/doc/refman/8.0/en/group-by-f...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question