1
I would like to understand how I can do a search in mysql skipping a certain amount of days of each record, for example, show the records from the beginning of a table to the end by skipping from 7 in 7 days, or from 1 in 1 month. I’ve done something similar limited, follow the code below:
SELECT `id`,`cod`,`corrente`,MIN(`data_hora`) as `data_hora` FROM sensores WHERE `cod` LIKE '001' GROUP BY DATE_FORMAT(`data_hora`, '%Y%m%d%H') ORDER BY `sensores`.`id` ASC
This code skips the records every 1 hour, follow other examples:
Intervalos por minuto = ... GROUP BY DATE_FORMAT(`data_hora`, '%Y%m%d%H%i')
Intervalos por hora = ... GROUP BY DATE_FORMAT(`data_hora`, '%Y%m%d%H')
Intervalos por dia = ... GROUP BY DATE_FORMAT(`data_hora`, '%Y%m%d')
It is efficient but I would like more options of intervals, such as 30 minutes, 7, 15 or 20 days.
I need this because I have a large number of records in a bank and it ends up getting too heavy to move all this to a graph.
You want to group by periods, right? What is your version of Mysql?
– Sorack
Have you tried?
group by DAY(campo_data) ,WEEK(campo_data), MONTH(campo_data), YEAR(campo_data)
, andDATE_ADD(campo_data, INTERVAL 10 DAY);
orDATE_ADD(campo_data, INTERVAL 15 MINUTE);
– Ivan Ferrer
The mysql version is 15.1
– Thiago
I tried, but he shows me a result of each day independent of the value in (field_data, INTERVAL 15 MINUTE);
– Thiago
Try to create a precedent for this.
– Pedro Filipe