clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2249262 fiddles created (32191 in the last week).

CREATE TABLE test (dt DATETIME, val INT)
 hidden batch(es)


INSERT INTO test WITH RECURSIVE cte AS ( SELECT '2019-01-01' dt UNION ALL SELECT dt + INTERVAL 1 DAY FROM cte WHERE dt < '2019-02-01' ) SELECT dt, ROUND(10 * RAND()) FROM cte
 hidden batch(es)


SELECT * FROM test
dt val
2019-01-01 00:00:00 4
2019-01-02 00:00:00 5
2019-01-03 00:00:00 1
2019-01-04 00:00:00 0
2019-01-05 00:00:00 8
2019-01-06 00:00:00 9
2019-01-07 00:00:00 3
2019-01-08 00:00:00 7
2019-01-09 00:00:00 6
2019-01-10 00:00:00 10
2019-01-11 00:00:00 1
2019-01-12 00:00:00 6
2019-01-13 00:00:00 6
2019-01-14 00:00:00 3
2019-01-15 00:00:00 7
2019-01-16 00:00:00 5
2019-01-17 00:00:00 2
2019-01-18 00:00:00 9
2019-01-19 00:00:00 6
2019-01-20 00:00:00 5
2019-01-21 00:00:00 4
2019-01-22 00:00:00 8
2019-01-23 00:00:00 5
2019-01-24 00:00:00 4
2019-01-25 00:00:00 6
2019-01-26 00:00:00 5
2019-01-27 00:00:00 6
2019-01-28 00:00:00 7
2019-01-29 00:00:00 5
2019-01-30 00:00:00 7
2019-01-31 00:00:00 8
2019-02-01 00:00:00 9
 hidden batch(es)


SELECT MIN(dt) `from`, MAX(dt) till, SUM(val) `sum` FROM test GROUP BY DATEDIFF(dt, '2018-12-31') DIV 7 -- литеральный эталонный понедельник 31 декабря 2018 года
from till sum
2019-01-01 00:00:00 2019-01-06 00:00:00 27
2019-01-07 00:00:00 2019-01-13 00:00:00 39
2019-01-14 00:00:00 2019-01-20 00:00:00 37
2019-01-21 00:00:00 2019-01-27 00:00:00 38
2019-01-28 00:00:00 2019-02-01 00:00:00 36
 hidden batch(es)


SELECT MIN(dt) `from`, MAX(dt) till, SUM(val) `sum` FROM test GROUP BY DATEDIFF(dt, (SELECT MIN(dt) - INTERVAL WEEKDAY(MIN(dt)) DAY FROM test)) DIV 7 -- вычисляемый эталонный понедельник
from till sum
2019-01-01 00:00:00 2019-01-06 00:00:00 27
2019-01-07 00:00:00 2019-01-13 00:00:00 39
2019-01-14 00:00:00 2019-01-20 00:00:00 37
2019-01-21 00:00:00 2019-01-27 00:00:00 38
2019-01-28 00:00:00 2019-02-01 00:00:00 36
 hidden batch(es)