Find out the number of concurrent users in some moment in time (f.ex. 12:00) of every day within provided dates. The table I have is id, login, logout as datetime
So I can get following: between 2018-04-01 and 2018-04-06 at noons there were 4 concurrent users at 2018-04-01 12:00, 5 at 2018-04-02 12:00 etc.
--------------------------------------
id login logout
--------------------------------------
1 2018-04-01 13:00 2018-04-02 13:00
2 2018-04-02 8:00 2018-04-04 16:00
make a query between two dates 2018-04-01 and 2018-04-03 for 12:00
-------------------------------------
date Number of conc.users
--------------------------------------
2018-04-01 0
2018-04-02 2
2018-04-03 1
That's what I got
set @DATE = '2018-04-01 12:00:00';
SELECT @DATE := DATE_ADD(@DATE, INTERVAL 1 DAY) AS DATE, COUNT(*) FROM Tasks WHERE start <= STR_TO_DATE(@DATE, '%Y-%m-%d %H:%i:%s') and end >= STR_TO_DATE(@DATE, '%Y-%m-%d %H:%i:%s')
I try to make a repeat query in order to dynamicly change the date, because it works this way
SELECT '2018-04-01 12:00:00' AS DATE, COUNT(*) FROM Tasks WHERE start <= STR_TO_DATE(@DATE, '%Y-%m-%d %H:%i:%s') and end >= STR_TO_DATE(@DATE, '%Y-%m-%d %H:%i:%s')
but just for one date