M
M
Melodic2015-12-18 18:45:32
PHP
Melodic, 2015-12-18 18:45:32

How to group results by range of days?

There is a query:
SELECT SUM(sum) AS sum,start_date
FROM aes_deposit WHERE user_id=1552 AND start_date BETWEEN '12/1/2015' AND '12/31/2015' GROUP BY start_date
which selects the amount of deposits and groups by date and then displays on the chart via js (date+amount).
How to make MySQL group by date range (2 days, 3 days, etc.)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-12-18
@Melodic

For starters, you have the wrong date format in your request. If VARCHAR or TEXT is used instead of the standard DATE type, then the search will not work correctly.
Well, for grouping, it is enough to create a function that will give the same values ​​for the quantities that need to be included in one group.
And, of course, indexes will not work with such a grouping.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question