Answer the question
In order to leave comments, you need to log in
How to count the number of records by intervals?
The table has a column that stores the time the record was created. The query specifies the end and start dates, then the interval is divided into n parts. And inside each such interval, you need to count the number of records from the database.
Tell me what to add to the request.
SELECT COUNT(*) quantity,
(timestamptz '2017-02-21 22:24:04+07' - timestamptz '2017-02-21 22:18:00+07')/n AS interval
FROM table
GROUP BY INTERVAL
ORDER BY INTERVAL;
Answer the question
In order to leave comments, you need to log in
first, in one way or another, you need to "classify" records by intervals:
- through case if they are constant and there are not many of them
- through some auxiliary table of intervals
- through "rounding" dates - such as day (), month () or diff / const
i.e. . the result should be a table with an interval_id column - now group by it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question