I have the below scenarios. Not sure if this can be achieved using SQL.

Data:

```
RECORD_SET, DATE_GAP, PREV_Record_start_ts, Bucket 

DIFF Y 01/01/1900 00:00:00 1 

SAME N 12/29/2013 23:59:59 1 

SAME N 02/11/2014 23:59:59 1 

SAME Y 12/22/2014 23:59:59 2 

SAME Y 06/10/2016 23:59:59 3 

SAME N 02/18/2017 23:59:59 3 

```

I have to derive the Bucket value based on the below rule:

If Record\_Set = DIFF and PREV\_RECORD\_START\_TS=1900 then set bucket to 1  

If Record\_set=SAME and Data\_Gap='N' then set bucket=prev\_bucket value else bucket=prev\_bucket value+1