2
I have the table below:
declare @order table (idOrder int, altcode varchar(17) )
insert into @order values (1,'11111111111')
insert into @order values (1,'22222222222')
insert into @order values (1,'33333333333')
insert into @order values (1,'44444444444')
insert into @order values (2,'72374949491')
insert into @order values (2, '11111111111')
insert into @order values (2,'66194701273')
insert into @order values (2,'22222222222')
insert into @order values (2,'33333333333')
insert into @order values (3,'87548758844')
insert into @order values (3, '11111111111')
insert into @order values (3,'734821919192')
insert into @order values (3,'22222222222')
insert into @order values (3,'33333333333')
insert into @order values (3,'74912817837')
insert into @order values (3,'67198191782')
insert into @order values (4,'77777777777')
insert into @order values (4, '11111111111')
insert into @order values (4,'771904749189')
insert into @order values (4,'33333333333')
insert into @order values (4,'88888888888')
insert into @order values (4,'99999999999')
insert into @order values (5,'88888888888')
insert into @order values (5,'781843741091')
insert into @order values (5,'33333333333')
insert into @order values (5,'99999999999')
insert into @order values (5,'77777777777')
I need to write a query to find all the orders and altcodes that any combination of 3 altcodes repeat in different orders.
For example: A query that works with the above table should find this:
O grupo de altcodes:
'11111111111'
'22222222222'
'33333333333'
são encontrados nas orders: 1, 2, 3
O grupo de altcodes:
'77777777777'
'88888888888'
'99999999999'
são encontrados nas orders: 4,5
O grupo de altcodes:
'33333333333'
'88888888888'
'99999999999'
são encontrados nas orders: 4,5
O grupo de altcodes:
'33333333333',
'77777777777',
'88888888888'
são encontrados nas orders: 4,5
O grupo de altcodes:
'33333333333',
'77777777777',
'99999999999'
são encontrados nas orders: 4,5
I’m having a hard time thinking of a query or algorithm with a cursor to solve this. I think there must be some easy command to solve this, but I can’t see it.
Welcome to the Stackoverflow in Portuguese. As the name suggests, the official language used here is Portuguese. So, could you please translate your question? If you prefer, you can also ask the same question on Stackoverflow website in English.
– Sorack