结果1来自表1:
select types from table1 where id = 123456;
结果:
934046, 934049
然后,结果1作为表2的参数:
select GROUP_CONCAT(name) from table2 where id in (
select types from table1 where id = 123456
);
但是,结果1是一个字符串值,因此结果:
NULL
事实上我想得到这个:
select GROUP_CONCAT(name) from table2 where id in ('934046', '934049');
or
select GROUP_CONCAT(name) from table2 where id in (934046,934049);
但可能还是这样:
select GROUP_CONCAT(name) from table2 where id in ('934046,934049');
1.
select REPLACE(types,',','\',\'') types from table1 where id=123456
1.1
result: 934046',' 934049
1.2
select GROUP_CONCAT(name) from table2 where ids in (
select REPLACE(types,',','\',\'') types from table1 where id=123456
);
2.
select CONCAT('\'',REPLACE(types ,',','\',\''),'\'') from table1 where
id=123456
2.1
reuslt: '934046',' 934049'
2.2
select GROUP_CONCAT(name) from table2 where ids in (
select CONCAT('\'',REPLACE(types ,',','\',\''),'\'') from table1 where
id=123456);
这个字符串值不能作为参数,我应该怎么做才能得到正确的ID?
2条答案
按热度按时间f4t66c6m1#
我用不同的查询创建了代码。
f0ofjuux2#
sql将如下所示:
使用函数concat()让t.id和类型具有相同的格式,然后使用locate()查找类型中是否存在t.id