首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求一 SQL 语句,多谢

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

求一 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

热点排行