So I have a table looks like this:
id value ts
123 T ts1
123 T ts2
123 F ts3
123 T ts4
456 F ts5
456 T ts6
456 T ts7
456 F ts8
......
What I want to do is to count the times when consecutive 'T' appears under each id partition(each id partition should be ordered by column ts). But not only that, I want to know how many times two consecutive 'T's appear; how many times three 'T's appear...
So finally, I want a table that has two columns:
num_of_consecutives
times_of_occurrences_for_this_number_of_consecutives
In this case, 2 consecutive 'T's appear one time and 1 consecutive T appears one time for id 123; 2 consecutive 'T's appear one time for id 456. Therefore, summing them up, the final table should look like this:
num_of_consecutives times_of_occurrences_for_this_number_of_consecutives
1 1
2 2