dimanche 10 juillet 2016

SQL Syntax for grouping by week-interval with certain date range

Suppose I have a dataset like this:

value   |   date
9       | 2016-06-02
2       | 2016-06-07

I have a query like :

SELECT SUM(`value`) AS `value`,  CONCAT(date, ' - ', date + INTERVAL 6 DAY) AS `date`
FROM test
GROUP BY TIMESTAMPDIFF(WEEK,DATE('2016-05-28'),DATE('2016-06-08'))

And hope it would be like this :

value   |   date
9       | 2016-05-28 - 2016-06-03
2       | 2016-06-04 - 2016-06-08

What am I missing? nb: The date in group by is user generated, and I know the 'select concat...' syntax is kinda wrong too, because it produces a different result that I want to get

Aucun commentaire:

Enregistrer un commentaire