On classic SQL: for all records with the status not S, we select such records for which the user_id matches, id is greater than or equal (that is, the same record), and status is not the same for S and there are no records with the status S for which The user matches the id between the two above. After that, the records are grouped by id from the first table (all records going without breaks will be with one id), count and check the necessary quantities. In this case, the user_id can be duplicated if it has several sections that are suitable for the conditions, so we use distinct.
select distinct A.user_id from Table1 A join Table1 B on B.user_id=A.user_id and B.id>=A.id and B.status!='S' and not exists(select 1 from Table1 C where C.user_id=A.user_id and C.status='S' and C.id>A.id and C.id<B.id ) where A.status!='S' group by A.id, A.user_id having count(1)>=5 and count(distinct B.lender_id)>=4
Example
Using variables, only for MySQL, should work much faster than the first, since in a single pass of the table. Here we introduce the rank variable which is incremented by 1 every time we encounter a record with status S. Thus, with the same rank there can be only one record with status S and several records immediately following it with other statuses. Records S are discarded, we consider the remaining records with the same rank.
select distinct user_id from ( select user_id, lender_id, status, @rank:=@rank+(status='S') rank from Table1 T, (select @rank:=0) i order by user_id, id ) X where status!='S' group by user_id, rank having count(1)>=5 and count(distinct lender_id)>=4
Example