Hi, i have a table like this:
| TIMESTAMP | FLOW |
| 18/07/2019 | 100 |
| 17/07/2019 | 110 |
| 16/07/2019 | 120 |
| 15/07/2019 | 120 |
| 14/07/2019 | 110 |
| 13/07/2019 | 13 |
| 12/07/2019 | 120 |
| 11/07/2019 | 120 |
| 10/07/2019 | 100 |
| 09/07/2019 | 12 |
| 08/07/2019 | 10 |
| 07/07/2019 | 100 |
| 06/07/2019 | 120 |
| 05/07/2019 | 3 |
| 04/07/2019 | 5 |
| 03/07/2019 | 6 |
| 02/07/2019 | 4 |
| 01/07/2019 | 3 |
| 30/06/2019 | 300 |
| 29/06/2019 | 200 |
| 28/06/2019 | 200 |
I need to do the average of the flow between a the period from TODAY() and another one in the past that follow this rule: FLOW<=20 FOR a period>=5gg. In the table above it would be between 18/07/2019 and 05/07/2019.
How can i write an SQL statement that can do that calculation for me?
Thanks a lot for your help