N:M data query where data is in a single table
I have a table with data for accounts and customers such that they form a N:M relationship. I wanted to query the table such that I get the N:1 data first followed by 1:M data grouped by as below (below the last customer involved in N:1 is same as first record in next set 1:M data). There are around 80k data in that table currently random and some repetitions and some not involved either in N:1 or 1:M. I am able to query independently N:1 and 1:M but not able to order them together as below (below the last customer