日期:2014-05-18  浏览次数:20440 次

求一 SQL 语句,谢谢
表中有五个字段   ABCDE   ,给定对应这五个地段值   abcde,   如何查找出任意三项匹配的记录
谢谢

------解决方案--------------------
建議加個keyID 字段
declare @keyID varcahr(10)
declare @icount int
set @icount = 0
if exists( select 1 from where A = 'a ' and KeyId = @keyID)
set @icount = @icount + 1
if exists( select 1 from where B = 'b ' and KeyId = @keyID)
set @icount = @icount + 1
if exists( select 1 from where C = 'c ' and KeyId = @keyID)
set @icount = @icount + 1
if exists( select 1 from where D = 'd ' and KeyId = @keyID)
set @icount = @icount + 1
if exists( select 1 from where E = 'e ' and KeyId = @keyID)
set @icount = @icount + 1
if @icount = 3
select * from tb1 where KeyID = @keyID