N
N
Nubbin2018-03-24 12:46:16
Laravel
Nubbin, 2018-03-24 12:46:16

Average time on site?

Good afternoon. Guys how to calculate the average time of activity on the site.
Table
id_user: - User ID
visit_date: - Date when the user entered
last_visit: - Date when the user left

[
   id_user:  1,
   visit_date: 'Зашел',
   last_visit: 'Ушел'
],[
   id_user:  1,
   visit_date: 'Зашел',
   last_visit: 'Ушел'
],[
   id_user:  1,
   visit_date: 'Зашел',
   last_visit: 'Ушел'
],[
   id_user:  2,
   visit_date: 'Зашел',
   last_visit: 'Ушел'
],[
   id_user:  3,
   visit_date: 'Зашел',
   last_visit: 'Ушел'
],[
   id_user:  1,
   visit_date: 'Зашел',
   last_visit: 'Ушел'
],

How now to calculate the average activity time of user "1" by two parameters (visit_date,last_visit)?
help me please

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Mashletov, 2018-03-24
@Nubbin

Walk through the array, calculate the difference last_visit - visit_date in seconds for a particular user. Collect all durations in an array and calculate the median.

N
Night, 2018-03-24
@maxtm

Everything is simple!
You make a request for the difference in seconds between in / out, take avg according to the result. Indexes cannot be used here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question