+---------------------+---------------+-------------------+----------------+
| created_at | verbrauch_ges | prev_verbauch_ges | day_diff |
+---------------------+---------------+-------------------+----------------+
| 2025-03-23 00:00:04 | 5628.79 | 5622.54345703125 | 6.2431640625 |
| 2025-03-22 00:00:06 | 5622.54 | 5615.43798828125 | 7.10546875 |
| 2025-03-21 00:00:11 | 5615.44 | 5609.4912109375 | 5.94677734375 |
| 2025-03-20 00:00:13 | 5609.49 | 5605.40380859375 | 4.08740234375 |
| 2025-03-19 00:00:17 | 5605.4 | 5600.44970703125 | 4.9541015625 |
| 2025-03-18 00:00:00 | 5600.45 | 5591.36279296875 | 9.0869140625 |
| 2025-03-17 00:00:03 | 5591.36 | 5585.2001953125 | 6.16259765625 |
| 2025-03-16 00:00:09 | 5585.2 | 5578.9580078125 | 6.2421875 |
| 2025-03-15 00:00:16 | 5578.96 | 5571.10498046875 | 7.85302734375 |
| 2025-03-14 00:00:04 | 5571.1 | 5560.3427734375 | 10.76220703125 |
| 2025-03-13 00:00:07 | 5560.34 | 5550.5400390625 | 9.802734375 |
| 2025-03-12 00:00:10 | 5550.54 | 5540.1171875 | 10.4228515625 |
| 2025-03-11 00:00:13 | 5540.12 | 5534.80908203125 | 5.30810546875 |
| 2025-03-10 00:00:16 | 5534.81 | 5528.48046875 | 6.32861328125 |
| 2025-03-09 00:00:18 | 5528.48 | 5521.70703125 | 6.7734375 |
| 2025-03-08 00:00:17 | 5521.71 | 5515.27392578125 | 6.43310546875 |
| 2025-03-07 00:00:11 | 5515.27 | 5510.17431640625 | 5.099609375 |
| 2025-03-06 00:00:14 | 5510.17 | 5504.083984375 | 6.09033203125 |
| 2025-03-05 00:00:06 | 5504.08 | 5497.21240234375 | 6.87158203125 |
| 2025-03-04 00:00:09 | 5497.21 | 5489.51904296875 | 7.693359375 |
+---------------------+---------------+-------------------+----------------+
SELECT min(created_at)created_at
,min(verbrauch_ges) verbrauch_ges
,lag(min(verbrauch_ges))over(order by created_at) prev_verbauch_ges
,min(verbrauch_ges)-coalesce(lag(min(verbrauch_ges))over(order by created_at),0.0) as day_diff
FROM pv_metrics
group by DATE(created_at)
ORDER BY ID DESC limit 20;
That's the answer or query I've needed.
Thanks