I am trying to write a query to get the last 4 weeks (Mon-Sun) of data. I want every week of data to be stored with an individual and shared table. every week data store based on name if same name repeated on single week amt should sum and if multiple name it should be show data individual, To see an example of what I am looking for, I have included the desired input and output below.
this is my table
| date | amt | name |
|---|---|---|
| 2022-04-29 | 5 | a |
| 2022-04-28 | 10 | b |
| 2022-04-25 | 11 | a |
| 2022-04-23 | 15 | b |
| 2022-04-21 | 20 | b |
| 2022-04-16 | 20 | a |
| 2022-04-11 | 10 | a |
| 2022-04-10 | 5 | b |
| 2022-04-05 | 5 | b |
i want output like this
| date | sum(amt) | name |
|---|---|---|
| 2022-04-25 to 2020-04-29 | 16 | a |
| 2022-04-25 to 2020-04-29 | 10 | b |
| 2022-04-18 to 2022-04-24 | 35 | b |
| 2022-04-11 to 2022-04-17 | 30 | a |
| 2022-04-04 to 2022-04-10 | 10 | b |
I would appreciate any pointers or 'best-practises' which I should employ to achieve this task.