Group Rows on the basis of nested hierarchy – find first predecessor in SQL/Redshift

I need to group records in a table on the basis of their first predecessor.
For eg. All subsequent mutations of group A should now have a column with a common value so I group/filter and see all of them together.

So far I have unsuccessfully tried connect by but that did not work the way I wanted.

Example Input and Output

  • Please don’t use images, add all information as editable text – so that someone can copy it if they want to try a solution. Also show the SQL that you’ve managed to write so far

    – 

Leave a Comment