Я пытаюсь определить, отличается ли набор значений от другого набора значений.
Это кажется простым, но я застрял на решении.
Вот данные ...
declare @tv_mccvalues table(recnum int identity(1,1) primary key, mcc int, pursecandoid int, candoid int)
--CanDoId 801 the MCC values are the same
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 5001, 801)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(2234, 5001, 801)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 6001, 801)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(2234, 6001, 801)
--CanDoId 901 the MCC values are the different
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 7001, 901)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(2234, 7001, 901)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 8001, 901)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(5234, 8001, 901)
--CanDoId 1001 the MCC values are the same
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 9001, 1001)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(2234, 9001, 1001)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 10001, 1001)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(2234, 10001, 1001)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 11001, 1001)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(2234, 11001, 1001)
--CanDoId 1101 the MCC values are different
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 12001, 1101)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(2234, 12001, 1101)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 13001, 1101)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(2234, 13001, 1101)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 14001, 1101)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(6234, 14001, 1101)
--CanDoId 1201 the MCC values are the same
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 15001, 1201)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 16001, 1201)
--CanDoId 1201 the MCC values are different
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(1234, 17001, 1301)
insert into @tv_mccvalues(mcc, pursecandoid, candoid) values(7234, 18001, 1301)
Главный ключ - кандоид.
Я пытаюсь выполнить запрос, подобный этому ...
declare @candoid int = 801
if exists(
select pursecandoid, mcc, count(mcc) as count
from @tv_mccvalues t
where candoid = @candoid
group by pursecandoid, mcc
having count(mcc) > 1
)
begin
select 'they are different'
end
else
begin
select 'the are the same'
end
Любая помощь приветствуется.