Well, I had not seen your desired output when I posted my post with example code below, but since there is no relation between the input that you had shown and the output that you are now showing, could you please provide the type of input from which you want to get the desired output. It is not obvious that you really need to store the data into a table to get the output you want if the input look like what I can, think of.