Home > Mobile >  MySQL how to fetch minute wise data, data frequency is 15 sec
MySQL how to fetch minute wise data, data frequency is 15 sec

Time:10-27

I have data like

2021-10-18 08:00:04
2021-10-18 08:00:19
2021-10-18 08:00:49
2021-10-18 08:01:04
2021-10-18 08:01:19
2021-10-18 08:01:34
2021-10-18 08:01:49
2021-10-18 08:02:20
2021-10-18 08:02:35
2021-10-18 08:20:08
2021-10-18 08:20:23
2021-10-18 08:20:38

and I tried with Aggregating MySQL data on hourly basis from minute-wise raw data

select timestamp, value  from table_1 group by round(unix_timestamp(timestamp)/(1 * 60));

it is giving me minute-wise data but at some point, it is giving 2 records for the same minute.

Output:
2021-10-18 08:00:04
2021-10-18 08:00:49
2021-10-18 08:01:34
2021-10-18 08:20:08
2021-10-18 08:20:38
2021-10-18 08:21:38
2021-10-18 08:22:39
2021-10-18 08:24:54

and my expected output like:-

    2021-10-18 08:00:04
    2021-10-18 08:01:34
    2021-10-18 08:20:08
    2021-10-18 08:21:38
    2021-10-18 08:22:39
    2021-10-18 08:24:54
enter code here

How can I solve this duplicate record for the same minute issue?

CodePudding user response:

use date, hour, minute functions

select max(timestamp)
from table_1 
group by date(timestamp), hour(timestamp), minute(timestamp)
  • Related