K
K
Kirill Petrov2017-10-18 17:23:30
MySQL
Kirill Petrov, 2017-10-18 17:23:30

How to group by date range in MySQL?

Greetings. Tell me how to group by date range in MySQL, for example, we take a date segment of 4 days, and group by it. Now I know how to group by day, month, week using DATE_FORMAT

SELECT DATE_FORMAT(datetime, "%d.%m.%Y") as `date`, `name`, SUM(value) AS `sum_val` FROM `log` GROUP BY `date`,`name`

And how to get a cut is valid from 10/10/2017, to 10/14/2017, from 10/15/2017, to 10/19/2017, etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-10-18
@Rsa97

Derive the formula. for example
GROUP BY DATEDIFF(`date`, '2017-10-10') DIV 4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question