I have the following table:
| weekStart | bcid |
|---|---|
| 2022-07-18 | df9bd190-417d-4007-9dc7-1de0a5ba4045 |
| 2022-07-25 | e46ac8ed-bcc5-4dab-9694-479637e1ee99 |
| 2022-08-01 | e46ac8ed-bcc5-4dab-9694-479637e1ee99 |
| 2022-08-01 | df9bd190-417d-4007-9dc7-1de0a5ba4045 |
| 2022-08-08 | df9bd190-417d-4007-9dc7-1de0a5ba4045 |
| 2022-08-08 | ca3fd5c6-73d0-4104-aa03-dcc0eb263c0a |
| 2022-08-08 | e46ac8ed-bcc5-4dab-9694-479637e1ee99 |
I need to find for every bcid the latest weekStart after which it appeared every "week" (i.e. group). That is, each value may appear consistently every week, then disappear and, at some point, come back. And I need the start date of this last (newest) group in which value started to appear consecutively again.
E.g. for df9bd190-417d-4007-9dc7-1de0a5ba4045 this should be 2022-08-01 and not 2022-07-18, because it was missing in 2022-07-25.
I currently think towards windowed functions, but not sure how to get to the "consecutively" part:
select bcid, min(min("weekStart")) over (partition by bcid) as "firstAppearedLatest"
from tx
group by bcid
Can assume that there are no weeks skipped between first and last weekStart values.