select distinct a.* from DP_MemberStore a left join DP_CommonSmsEntries b on a.MemberId = b.MemberId and a.StoreId = b.StoreId and b.Instruction = 'XS' where b.Instruction is null
嗯,刚好相反,我稍微改了一下,输出的是了 结果对了,我测试下逻辑对不对先,代码是这样的SELECT MemberId FROM dbo.DP_MemberStore WHERE MemberId NOT IN ( select distinct a.MemberId from DP_MemberStore a left join DP_CommonSmsEntries b on a.MemberId = b.MemberId and a.StoreId = b.StoreId and b.Instruction = 'XS' where b.Instruction is NULL)
但我的意思应该是只输出
因为只有这个会员的门店全部上报了XS,而其他两个会员都还有门店没上报XS
from DP_MemberStore a
left join DP_CommonSmsEntries b
on a.MemberId = b.MemberId
and a.StoreId = b.StoreId
and b.Instruction = 'XS'
where b.Instruction is null
结果对了,我测试下逻辑对不对先,代码是这样的SELECT MemberId FROM dbo.DP_MemberStore WHERE MemberId NOT IN (
select distinct a.MemberId
from DP_MemberStore a
left join DP_CommonSmsEntries b
on a.MemberId = b.MemberId
and a.StoreId = b.StoreId
and b.Instruction = 'XS'
where b.Instruction is NULL)