Answer the question
In order to leave comments, you need to log in
GROUP BY weeks; How to display a range?
SELECT
DATE_FORMAT(`start_date`, '%x-%v') weeks,
COUNT(*)
FROM `events` GROUP BY weeks;
Answer the question
In order to leave comments, you need to log in
This option:
SELECT
DATE_FORMAT(`start_date`, '%x-%v') weeks,
COUNT(*), DATE_ADD(`start_date`, INTERVAL(2-DAYOFWEEK(`start_date`)) DAY) first_date,
DATE_ADD(`start_date`, INTERVAL(8-DAYOFWEEK(`start_date`)) DAY) last_date
FROM `events` GROUP BY weeks;
So it won't work?
SELECT
DATE_FORMAT(`start_date`, '%x-%v') weeks,
MAX(`start_date`), MIN(`start_date`)
COUNT(*)
FROM `events` GROUP BY weeks;
Group with lines - IMHO will be a bit slow.
If in a locale, I would time it like this: form a week string, a numerical week number, a counter; would group by the numerical number of the week, would select two columns in the application.
If the load on the network is too large due to the numerical week number, I would leave it as you have, except that the line format would be changed to the one you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question