I have a database with the following records
I want to create a query resulting in
How can I get this result? Trying for hours now, but cannot figure this out.
Code:
+--------------+------------+-------------+---------+
| period_start | period_end | customer_id | revenue |
+--------------+------------+-------------+---------+
| 1-1-2023 | 31-3-2023 | 1 | 1000 |
| 1-4-2023 | 30-06-2023 | 1 | 1500 |
| 12-1-2023 | 31-3-2023 | 2 | 1000 |
| 1-4-2023 | 30-06-2023 | 2 | 1900 |
| 1-1-2023 | 31-5-2023 | 3 | 1200 |
+--------------+------------+-------------+---------+
I want to create a query resulting in
Code:
+-------------+--------------+------------+---------+
| customer_id | period_start | period_end | revenue |
+-------------+--------------+------------+---------+
| 1 | 01-01-2023 | 20-06-2023 | 2500 |
| 2 | 12-01-2023 | 30-06-2023 | 2900 |
| 3 | 1-1-2023 | 31-5-2023 | 1200 |
+-------------+--------------+------------+---------+
How can I get this result? Trying for hours now, but cannot figure this out.