I have table in MySQL with times spent by customers and I need to find the most busy 30 mins.
CREATE TABLE Customer
(id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
customerId int NOT NULL,
arrival datetime,
leaving datetime);
INSERT INTO Customer
(customerId, arrival, leaving)
VALUES
(1, '2018-01-01 10:00:00', '2018-01-01 12:00:00'),
(2, '2018-01-01 11:00:00', '2018-01-01 12:00:00'),
(3, '2018-01-01 11:30:00', '2018-01-01 12:30:00'),
(4, '2018-01-01 13:30:00', '2018-01-01 14:30:00')
;
Expected result is something like multiplerows with time and number of customers:
10:00 10:30 1
10:30 11:00 1
11:00 11:30 2
11:30 12:00 3
12:00 12:30 1
I can easily make 5 sql queries and get the result (I made some view in similar problem https://stackoverflow.com/a/59478411/11078894 ), but I do not know how to get the result with 1 query.
Please how to make subintervals in MySQL? Thx