У меня есть две таблицы. #tempinfo содержит номер заказа и имя клиента. #tempproduct содержит номер заказа, имя клиента и заказанные продукты.
Мне нужно найти продукты, которые существуют в одном заказе для клиента, но отсутствуют в другом заказе для клиента.
create table #tempinfo (OrderNumber int, Client varchar(25))
create table #tempproduct (productid int, OrderNumber int, Client varchar(25), Products varchar(50)
insert into #tempinfo values (1, 'Albertsons')
insert into #tempinfo values (2, 'Albertsons')
Insert into #tempinfo values (3, 'Krogers')
Insert into #tempinfo values (4, 'Krogers')
Insert into #tempinfo values (5, 'Krogers')
Insert into #tempinfo values (6, 'Smiths')
Insert into #tempinfo values (7, 'Smiths')
insert into #tempproduct (1, 1, 'Albertsons', 'Oranges')
insert into #tempproduct (2, 1, 'Albertsons', 'Apples')
insert into #tempproduct (3, 2, 'Albertsons', 'Oranges')
insert into #tempproduct (4, 2, 'Albertsons', 'Apples')
insert into #tempproduct (5, 2, 'Albertsons', 'Grapes')
insert into #tempproduct (6, 3, 'Krogers', 'Pencils')
insert into #tempproduct (7, 3, 'Krogers', 'Pens')
insert into #tempproduct (8, 3, 'Krogers', 'Staples')
insert into #tempproduct (9, 5, 'Krogers', 'Pencils')
insert into #tempproduct (10, 5, 'Krogers', 'Erasers')
insert into #tempproduct (11, 6, 'Smiths', 'Soda')
insert into #tempproduct (12, 6, 'Smiths', 'Buns')
insert into #tempproduct (13, 6, 'Smiths', 'Ice')
insert into #tempproduct (14, 7, 'Smiths', 'Buns')
Хотелось бы увидеть:
Альбертсонс порядка 1 отсутствует "Виноград"
Крогерс ордена 3 отсутствует «Ластики»
В Крогерсе 5-го порядка отсутствуют «Ручки» и «Скрепки»
В киме порядка 7 отсутствуют «Сода» и «Лед»