/**
根据testId 查询信息
**/
DROP FUNCTION if exists f_searchAAAById;
CREATE FUNCTION f_searchAAAById(testId INTEGER)
RETURNS VARCHAR(1000)
BEGIN
/**
说明:1、根据AAA id查询vals
**/
DECLARE vals varchar(10000) default '';
declare i int default 0;
IF testId is NULL THEN
SET vals='';
ELSE
/* 1、获取id集合*/
SELECT aaa,bbb INTO @V1, @V2
from AAA tmn,BBB mmn WHERE tmn.flag=1
AND mmn.flag=1 AND tmn.b_id=mmn.id AND tmn._id=testId LIMIT 1;
/* 2、查询emal地址*/
SELECT GROUP_CONCAT(field1) INTO vals from (
SELECT field1 FROM user_info WHERE instr(concat('#',@V1,'#'),concat('#',id,'#'))
UNION
SELECT field1 from user_info WHERE field1 !='' AND id in(
SELECT user_id from CCC where flag=1 AND
instr(concat('#',@V2,'#'),concat('#',field2,'#')))) a;
END IF;
RETURN vals;
END