name id
成都 1
成都 2
成都 3
商场 2
商场 3
商场 4
人民 3
人民 4
人民 5
用sql查找出 '成都' 和 '商场' 和 '人民' 的交集 ,能运行的哈!!肯能还会添加条件 ('成都'‘新世纪’‘人民’‘商场’)id
3
成都 1
成都 2
成都 3
商场 2
商场 3
商场 4
人民 3
人民 4
人民 5
用sql查找出 '成都' 和 '商场' 和 '人民' 的交集 ,能运行的哈!!肯能还会添加条件 ('成都'‘新世纪’‘人民’‘商场’)id
3
group by id having count(*)>=2
select id from tt where name in('成都','商场','人民')
group by id having count(*)>=3
DELIMITER $$
drop procedure if exists ttcfcx$$
CREATE PROCEDURE `zz`.`ttcfcx`(in ee varchar(200))
BEGIN
set @ff1=length(ee)-length(replace(ee,',',''))+1;
set @ff=concat('select id from ttcf where name in (',ee,') group by id having count(*)>=',@ff1);
select @ff;
prepare rr from @ff2;
execute rr;
END$$DELIMITER ;call ttcfcx("'成都','商场','人民'")
假设以逗号为分隔符
我意思是,取他们结果的 交集 (id列) name id
成都 1
成都 2
成都 3——(number1)
商场 2
商场 3——(number2)
商场 4
人民 3——(number3)
人民 4
人民 5 交集!
谢谢了!
前辈,我怎么创建不了 这个存储过程啊? 我的数据库 是 lucenesearch 表是 testa !!!
prepare rr from @ff2->prepare rr from @ff
DELIMITER $$DROP PROCEDURE IF EXISTS `zz`.`ttZfcx`$$CREATE DEFINER=`root`@`localhost` PROCEDURE `ttZfcx`(in ee varchar(200))
BEGIN
DECLARE DD INT;
DECLARE DD1 VARCHAR(200);
Set DD=length(ee)-length(replace(ee,',',''))+1;
SET DD1=CONCAT('select id from ttGH4 where name in (',ee,') group by id having count(*)>=',DD);
SET @FF=DD1;
prepare rr from @ff;
execute rr;
END$$DELIMITER ;
结贴吧。
不过,wwwwa 和 wwwwb 这两个帐号都这面高的级别,真是不容易啊。