I need to get a preceding row even if doesn't match conditions in WHERE. Here is my data:
I need to get the request_id of the row preceding the row with flag=true In example above it would be the one at 2022-09-10 07:02:04 (please disregard the hilghlight, I didn't notice there is earlier one)
I can use LAG:
SELECT LAG(request_id, 1) OVER (PARTITION BY session_id ORDER BY time)
FROM table
WHERE flag=true
But flag=true conditon will apply to LAG function too.
Is there a way to do it?
