Please tell how to group by 7 days for current quarter without using nested query. It should be like :
Week_period Date Clicks
1 1-10-2016 To 07-10-2016 30
2 8-10-2016 To 14-10-2016 40
3 15-10-2016 To 28-10-2016 20
4 29-10-2016 To 04-11-2016 10
5 05-11-2016 To 11-11-2016 80
6 12-11-2016 To 18-11-2016 90
And will continue till 31-12-2016
CREATE TABLE IF NOT EXISTS `user_click` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` datetime NOT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Thanks for the help.. I modified the code as listed below :
SELECT STR_TO_DATE(CONCAT(YEARWEEK(`date`), ' Sunday'), '%X%V %W') week_start,
STR_TO_DATE(CONCAT(YEARWEEK(`date`), ' Saturday'), '%X%V %W') week_end,
SUM(id) clicks
FROM `user_click` where QUARTER(`date`) = QUARTER(CURRENT_DATE())
GROUP BY YEARWEEK(`date`)
But it gives a date from september as well which is not right. Currently I am getting output as :
week_start week_end clicks
2016-09-25 2016-10-01 1
2016-10-02 2016-10-08 70
But the result required does not matches as i want result depend upon the days ie 1st october to 7th october as described earlier. Please help regarding this regard