add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
version()
5.7.33
id quantity dt_start dt_END
1 100 2021-01-14 10:00:00 2021-01-16 10:00:00
2 125 2021-01-14 10:00:00 2021-01-16 10:00:00
4 50 2021-01-14 10:00:00 2021-01-19 10:00:00
7 100 2021-01-16 10:00:00 2021-01-19 10:00:00
8 200 2021-01-16 10:00:00 2021-01-19 10:00:00
6 75 2021-01-16 10:00:00 2021-01-21 10:00:00
3 200 2021-01-17 10:00:00 2021-01-23 10:00:00
9 50 2021-01-18 10:00:00 2021-01-19 10:00:00
5 100 2021-01-21 10:00:00 2021-01-23 10:00:00
10 150 2021-01-21 10:00:00 2021-01-23 10:00:00
the_sum period
275 per_1
625 per_2
250 per_3
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(ORDER BY the_sum DESC) AS rn 
  FROM
  (
    SELECT SUM(quantity) AS the_sum,
 ' at line 10
id quantity dt_start dt_END
11 100 2021-01-14 10:00:00 2021-01-16 10:00:00
12 125 2021-01-14 10:00:00 2021-01-16 10:00:00
13 200 2021-01-17 10:00:00 2021-01-23 10:00:00
14 50 2021-01-14 10:00:00 2021-01-19 10:00:00
15 100 2021-01-21 10:00:00 2021-01-23 10:00:00
16 75 2021-01-16 10:00:00 2021-01-21 10:00:00
17 100 2021-01-16 10:00:00 2021-01-19 10:00:00
18 200 2021-01-16 10:00:00 2021-01-19 10:00:00
19 50 2021-01-18 10:00:00 2021-01-19 10:00:00
20 150 2021-01-21 10:00:00 2021-01-23 10:00:00
21 220 2021-01-25 10:00:00 2021-01-25 10:00:00
quantity year month day
100 2021 1 14
125 2021 1 14
50 2021 1 14
75 2021 1 16
100 2021 1 16
200 2021 1 16
200 2021 1 17
50 2021 1 18
100 2021 1 21
150 2021 1 21
220 2021 1 25
SUM(t.quantity) year month day
275 2021 1 14
375 2021 1 16
200 2021 1 17
50 2021 1 18
250 2021 1 21
220 2021 1 25
The date: Sum from:
2021-01-12 0
2021-01-13 0
2021-01-14 275
2021-01-15 0
2021-01-16 375
2021-01-17 200
2021-01-18 50
2021-01-19 0
2021-01-20 0
2021-01-21 250
2021-01-22 0
2021-01-23 0
2021-01-24 0
2021-01-25 220
2021-01-26 0
2021-01-27 0
2021-01-28 0