给定一组数据group1
a b c d e f
a b d e f g
a b e d h f
a b d h i o
a b c d f h给定数据group2
a b d f c h 求sql语句,找出group1中与group2中至少4个一样的数据
我要的结果是
同时包含group2中任意四个的数据
就是a b c d e f这个符合,它包含a b d f.
谢谢各位了!!
a b c d e f
a b d e f g
a b e d h f
a b d h i o
a b c d f h给定数据group2
a b d f c h 求sql语句,找出group1中与group2中至少4个一样的数据
我要的结果是
同时包含group2中任意四个的数据
就是a b c d e f这个符合,它包含a b d f.
谢谢各位了!!
from yourTable
where if(INSTR(group1,'a')>0,1,0)+
if(INSTR(group1,'b')>0,1,0)+
if(INSTR(group1,'d')>0,1,0)+
if(INSTR(group1,'f')>0,1,0)+
if(INSTR(group1,'e')>0,1,0)+
if(INSTR(group1,'h')>0,1,0) >=4不知道你的表结构,只能大概猜一下了。
表名 yourTable 内有一个字段 group1 内容为
group1
-------------
'a b c d e f'
'a b d e f g'
'a b e d h f'
'a b d h i o'
'a b c d f h'问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)
'a b c d e f'
这是6个字段
问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)只好继续猜你的表名和字段名。select *
from yourTable
where if(instr('a b d f c h',col1)>0,1,0) +
if(instr('a b d f c h',col2)>0,1,0) +
if(instr('a b d f c h',col3)>0,1,0) +
if(instr('a b d f c h',col4)>0,1,0) +
if(instr('a b d f c h',col5)>0,1,0) +
if(instr('a b d f c h',col6)>0,1,0) >=4;
给定数据group2以逗号分隔,a,b,d,f,c,hselect *
from tt
where if(instr(concat(',',group2,','),concat(',',col1,','))>0,1,0) +
if(instr(concat(',',group2,','),concat(',',col2,','))>0,1,0) +
if(instr(concat(',',group2,','),concat(',',col3,','))>0,1,0) +
if(instr(concat(',',group2,','),concat(',',col4,','))>0,1,0) +
if(instr(concat(',',group2,','),concat(',',col5,','))>0,1,0) +
if(instr(concat(',',group2,','),concat(',',col6,','))>0,1,0) >=4;