my brains are tired :)and ideas on this one :)to populate the table.create table purchase(custID int,OrderOrder int,channel varchar(20))insert into purchase select 1123,1,'television' union ALL select 1123,2,'television' union ALL select 1123,3,'television' union ALL select 1126,1,'television' union ALL select 1126,2,'radio' union ALL select 1120,1,'television' union ALL select 1122,1,'television' union ALL select 1122,2,'television' union ALL select 1122,3,'internet' union ALL select 1115,1,'internet' union ALL select 1115,2,'television' union ALL select 1115,3,'internet' union ALL select 1115,4,'television'
and this is desired outputdesired outputcustID orderOrder channel r_n1115 1 internet 11115 2 television 31115 3 internet 31115 4 television 31120 1 television 11122 1 television 11122 2 television 21122 3 internet 31123 1 television 11123 2 television 21123 3 television 21126 1 television 11126 2 radio 3r_n = row order- 1 - first order- 2 - all next orders with same channel as first order- 3 - all next orders with different channel as first order