I'm trying to grab the max value in a column up to and including the current row. In the xample below, I've ordered the table by date. I would like to calculate the value of rollingMaxSource as shown. Starting from the top, it reports the max value found up to that point. I then compare the max value to the source value. If source is lower than max, I flag it, since with this ordering the value of source should only be equal to or higher than the previous row.
Can this be done in MySQL?
| Account | Source | rollingMaxSource | flag | date |
|---|---|---|---|---|
| 1 | 10 | 10 | false | 2022-05-01 |
| 1 | 10 | 10 | false | 2022-06-01 |
| 1 | 9 | 10 | true | 2022-07-01 |
| 1 | 10 | 10 | false | 2022-08-01 |
| 1 | 11 | 11 | false | 2022-09-01 |