I'm a fairly new Postgres user, I'm sure there's an answer to this already but I can't find it.
I have three tables:
Tasks :
| id | start_date | end_date |
| --- | ---------- | ---------- |
|1 | 2021-01-27 | 2021-03-27 |
|2 | 2021-02-21 | 2021-04-27 |
Employe :
| id | name |
| --- | -------------- |
| 1 | Linus Torvalds |
Employe_task:
| id | employe_id| task_id|amount|
| --- | --------- |------- |----- |
| 1 | 1 | 1 | 2 |
| 2 | 1 | 2 | 1 |
I need to sum quantity within the same interval and calculate the start_date and end_date.
I'm looking for a query to get this result:
| amount | name | start_date|end_date |
| ------ | ------------ |---------- |--------- |
| 2 |Linus Torvalds| 2021-01-27|2021-02-21|
| 3 |Linus Torvalds| 2021-02-21|2021-03-27|
| 1 |Linus Torvalds| 2021-03-27|2021-04-27|
I created a sqlfiddle to make it simpler.