на примере наверное лучше показать, я сравниваю:
SELECT ContentID, t, count(*)
FROM tracks
WHERE StartTime BETWEEN '2019-07-05 00:00:00' AND '2019-07-05 02:59:59'
GROUP BY ContentID, toStartOfInterval(StartTime, INTERVAL 3 HOUR) as t
UNION ALL
SELECT ContentID, t, count(*)
FROM tracks
WHERE StartTime BETWEEN '2019-07-05 03:00:00' AND '2019-07-05 05:59:59'
GROUP BY ContentID, toStartOfInterval(StartTime, INTERVAL 3 HOUR) as t
UNION ALL
SELECT ContentID, t, count(*)
FROM tracks
WHERE StartTime BETWEEN '2019-07-05 06:00:00' AND '2019-07-05 06:59:59'
GROUP BY tracks.ContentID, toStartOfInterval(StartTime, INTERVAL 3 HOUR) as t;
….
и это:
SELECT ContentID, toStartOfInterval(StartTime, INTERVAL 3 HOUR) as t, count()
FROM tracks
WHERE StartTime BETWEEN '2019-07-05 00:00:00' AND '2019-07-05 29:59:59'
GROUP BY ContentID, t;
Не очень понятно зачем в первом запросе группировать если там и так 3-часовые интервалы?
Обсуждают сегодня