帮助!这是我需要完成的一个非常简单的 a、b、c 示例。我一直在拔头发。我以前写过这个,但现在无法理解它!就是这样,实际和预期的结果如下所示:
set nocount on
declare @a table (id int, a varchar(10))
declare @b table (ref int, b varchar(10), c varchar(20))
insert into @a select 1, 'bingo'
insert into @a select 2, 'bongo'
insert into @b select 1, 'T5', 'asdfwef'
insert into @b select 1, 'T8', 'asfqwez'
insert into @b select 1, 'T6', 'qweoae'
insert into @b select 1, 'T8', 'qzoeqe'
insert into @b select 1, 'T9', 'oqeizef'
insert into @b select 2, 'T3', 'awega'
insert into @b select 2, 'T6', 'fhaeaw'
insert into @b select 2, 'T3', 'fqsegw'
select * from @a a join @b b on a.id = b.ref
-- Expected (Uniqueness is: a’s id to b’s ref and the first b value ingoring b’s c value)
----1,bingo,1,T5,asdfwef
----1,bingo,1,T8,asfqwez
----1,bingo,1,T6,qweoae
----1,bingo,1,T9,oqeizef
----2,bongo,2,T3,awega
----2,bongo,2,T6,fhaeaw
-- Actual
----1,bingo,1,T5,asdfwef
----1,bingo,1,T8,asfqwez
----1,bingo,1,T6,qweoae
----1,bingo,1,T8,qzoeqe
----1,bingo,1,T9,oqeizef
----2,bongo,2,T3,awega
----2,bongo,2,T6,fhaeaw
----2,bongo,2,T3,fqsegw