A
A
Alexey Lebedev2015-11-07 18:49:25
MySQL
Alexey Lebedev, 2015-11-07 18:49:25

How to display the points that are in the interval?

Terribly worded.
However, everything is easier. We have
3 columns: 1 )
user id 2
) session start time (unixtime)
3) session end time ( unixtime ) users online by the hour. Let 's say 18:00-19:00 - 10 people online. 19:00-20:00 - 15 people online. Is there a simple solution option? Because 24 requests of this kind come to my mind

SELECT count(1) FROM table WHERE time_end>@time_end and time_start<@time_start;

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Immortal_pony, 2015-11-07
@Immortal_pony

If the sessions are not very long and there is no need for an exact value, then this:

SELECT 
  COUNT(`id`),
  DATE_FORMAT(`start`, '%Y%m%d%H') AS 'hour'
FROM 
  `users`
WHERE 1
  GROUP BY `hour`

A
Artem Mudryak, 2015-11-07
@artem_1403

I would make a reference, with the necessary time intervals (let's say a day divided by 1 hour), call it calendar , and make a JOIN, with the following constraint:
calendar.MyHour between "session start time" and "session end time" .
Thus, we multiply each row of the original table by the number of time intervals that it covers.
I immediately see 1 more place to work out, if the time interval spans several days, then we need a second reference book, with days, I have one called DAYS , where a list of dates (in the past and future) with a bunch of useful information on the calendar, we work with it in a similar way .
If I didn't understand something, I can elaborate...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question