mysql中如何拆分 现在有一个ids字段是'11,22,33',是另外一张表的id。但是在检索的时候 id IN (ids),这里的ids是作为一个字符串,而不是‘11’,‘22’,‘33’.mysql中有什么方法吗 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用FIND_IN_SETselect * from table1where FIND_IN_SET(id,ids) delimiter //drop procedure if exists spFind;CREATE PROCEDURE `spFind`(ids varchar(30))beginset @s=concat('select * from t2 where id in(',ids,')');select @s;prepare stmt1 from @s;execute stmt1;DEALLOCATE PREPARE stmt1;end;//delimiter ;存储过程;127.0.0.1~root@localhost~test>select * from t2;+----+-----+-------+| id | id1 | sname |+----+-----+-------+| 3 | 2 | a || 4 | 3 | a || 8 | 4 | a || 1 | 10 | a |+----+-----+-------+4 rows in set (0.00 sec)127.0.0.1~root@localhost~test>call spFind('4,3');+-----------------------------------+| @s |+-----------------------------------+| select * from t2 where id in(4,3) |+-----------------------------------+1 row in set (0.00 sec)+----+-----+-------+| id | id1 | sname |+----+-----+-------+| 3 | 2 | a || 4 | 3 | a |+----+-----+-------+2 rows in set (0.00 sec)Query OK, 0 rows affected (0.00 sec) myql服务器启动不了 MYSQL1048错误到底怎么解决啊 关于超大型网站的数据库备份问题 请大家看一下,我这两个sql语句的效率问题 MYSQL一对多,单向关联 查找对应栏目最新的5条新闻! 短日期类型的字段如何设置变量才能正常查出表中数据 我在装mysql时出现的问题! 我在MYSQL下误删了数据,我要怎样才能恢复过来? 请各位mysql高人帮忙 无聊!散分! NDB Cluster同时用于读写有什么潜在问题 谁能帮忙 循环插入 数据的例子
where FIND_IN_SET(id,ids)
delimiter //
drop procedure if exists spFind;
CREATE PROCEDURE `spFind`(ids varchar(30))
begin
set @s=concat('select * from t2 where id in(',ids,')');
select @s;
prepare stmt1 from @s;
execute stmt1;
DEALLOCATE PREPARE stmt1;
end;
//
delimiter ;存储过程;
127.0.0.1~root@localhost~test>select * from t2;
+----+-----+-------+
| id | id1 | sname |
+----+-----+-------+
| 3 | 2 | a |
| 4 | 3 | a |
| 8 | 4 | a |
| 1 | 10 | a |
+----+-----+-------+
4 rows in set (0.00 sec)127.0.0.1~root@localhost~test>call spFind('4,3');
+-----------------------------------+
| @s |
+-----------------------------------+
| select * from t2 where id in(4,3) |
+-----------------------------------+
1 row in set (0.00 sec)+----+-----+-------+
| id | id1 | sname |
+----+-----+-------+
| 3 | 2 | a |
| 4 | 3 | a |
+----+-----+-------+
2 rows in set (0.00 sec)Query OK, 0 rows affected (0.00 sec)