When I take the data from a database with a one-second interval that time only available DateTime
interval output count gets and missing some DateTime
interval from the output.
I fill all missing DateTime
intervals with count 0.
Example:
if start date: 2019-10-15 02:36:23
then
end date : 2019-10-15 03:36:22
get one-hour data with one-second intervals if that time not available any count then get 0 counts.
mysql> select start_date,count(id) as count from live_login where start_date >= '2019-10-15 02:36:23' GROUP BY UNIX_TIMESTAMP(start_date) DIV 1;
+---------------------+-------+
| start_date | count |
+---------------------+-------+
| 2019-10-15 02:36:23 | 1 |
| 2019-10-15 02:36:24 | 1 |
| 2019-10-15 02:36:26 | 1 |
| 2019-10-15 02:36:55 | 1 |
| 2019-10-15 02:36:57 | 1 |
| 2019-10-15 02:37:08 | 1 |
Output need like this:
| start_date | count |
+---------------------+-------+
| 2019-10-15 02:36:23 | 1 |
| 2019-10-15 02:36:24 | 1 |
| 2019-10-15 02:36:25 | 0 |
| 2019-10-15 02:36:26 | 1 |
| 2019-10-15 02:36:27 | 0 |
| 2019-10-15 02:36:28 | 0 |
| 2019-10-15 02:36:29 | 0 |
| 2019-10-15 02:36:30 | 0 |
| 2019-10-15 02:36:31 | 0 |
| 2019-10-15 02:36:32 | 0 |
| 2019-10-15 02:36:33 | 0 |
| 2019-10-15 02:36:34 | 0 |
| 2019-10-15 02:36:35 | 0 |