当前位置: 代码迷 >> Sql Server >> 求一 SQL 语句,多谢
  详细解决方案

求一 SQL 语句,多谢

热度:45   发布时间:2016-04-27 18:48:38.0
求一 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
  相关解决方案