MySQL query - Passing variable into subquery's derived table
Use GROUP BY
And transform the &quot;week&quot; into a number that can be used in the GROUP BY:  FLOOR((TO_DAYS(createdTime) - 1)/7).  As a simple test:
SELECT FLOOR((TO_DAYS(CURDATE()) - 1)/7);
+-----------------------------------+
| FLOOR((TO_DAYS(CURDATE()) - 1)/7) |
+-----------------------------------+
|                            105446 |
+-----------------------------------+

That FLOOR expression gives you a &quot;week number&quot; that for use with GROUP BY.  (Tweek the &quot;-1&quot; if I don't have the week starting on the right day of week.)  You can derive &quot;start&quot; and &quot;end&quot; from that number via some simple expressions like
SELECT FROM_DAYS(105446 * 7) AS 'start',
       FROM_DAYS(105446 * 7 + 6) AS 'end';
+------------+------------+
| start      | end        |
+------------+------------+
| 2020-11-28 | 2020-12-04 |
+------------+------------+