I'm not even seeing the logic between the 3 columns of the original data and the rows that appear to have more than three values.
Please post your table DDL and an INSERT statement for your data so we can see how the data fits in these columns. Then post an english language version (as opposed to a code version) of what you are trying to achieve with the results.