A Table:
col1 col2 col3 col4
17 5678 abc mno
16 5678 abc mno
15 5678 abc mno
14 5678 abc mno
13 5678 abc mno
10 1234 def pqr
I want to create a column output with either value 'a' or 'b'
col1 col2 col3 col4 output
17 5678 abc mno b
16 5678 abc mno a
15 5678 abc mno b
14 5678 abc mno b
13 5678 abc mno a
10 1234 def pqr a
For a partition by (or group) of columns namely col3, col4 and order by col1 and col2, output is marked the value of 'a' the first occurrence of that group (row 5 for example), this row marks an event which can last 3 consecutive times, after which again output column should be marked 'a' (example, row 2) if col1 is in sequence.