一个字符串‘3;6;7;15;35;99;’
如何查询得到
xx
--
3
6
7
15
35
99
如何查询得到
xx
--
3
6
7
15
35
99
解决方案 »
- 救救俺啊,存储过程创建不了了
- 关于oracle迁移到mysql中sequence的问题
- MYSQL数据恢复
- 请推荐一本MySQL书,刚学习,非常感谢!
- 请教一个mysql数据库性能问题!
- 高分求助mysql存储过程问题
- mysql 数据库安装后, 进入doc输入密码, 显示了welcome和版本号,后面出现了提示符 mysql> ,输入常用命令 都不管用,什么原因?
- 我的MySQL 启动不了啦
- 在Mysql中居然字符 林=丽,为什么呢?请问哪位大侠也遇过?
- 在mysql中怎么把文件里的内容写到表中啊!!!!!
- cidr的insert问题
- postgresql v8.3.1 所有的postgres进程均结束了。why?
[/align]
LEN(REPLACE('3;6;7;15;35;99',';',''))取得有多少个;
1、用循环执行
ff=SUBSTRING_INDEX('3;6;7;15;35;99',';', i)取値,
2、
REPLACE('3;6;7;15;35;99',ff,'')刷新字符串,重新执行执行第一步思路如此,用要一个存储过程来完成
#建表测试代码
create table test1
(`strA` varchar(20) NOT NULL);
create table test2
(`strB` varchar(20) NOT NULL);
insert into test1 values('2;5;7;13;55;108;266;');
insert into test2 values('2;7;13;108;');
#表中的strA,strB长度是不限的,元素间以;分隔,strB中的元素一定在strA中有。
目标
XX FLAG
--------
2 1
5 0
7 1
13 1
55 0
108 1
266 0
请大家帮忙呀!
2。是否是只能用SQL语句实现?
[align=center]==== 思想重于技巧 ====
[/align]
如果可以,我可以帮你写个store procedure, 不过你的mySQL version >5
2。是否是只能用SQL语句实现?
比较复杂,但亦可实现说明你的要求,省得我做两种方案
[align=center]==== 思想重于技巧 ====
[/align]
很感谢
[/align]
select substring_index(@str,';',1);
select substring(substring_index(@str,';',2),instr(substring_index(@str,';',2),';')+1);...
今天要开会,如果没人帮你写的话,明天帮你写一下[align=center]==== 思想重于技巧 ====
[/align]
role (rid, ...)
permission ( rid, perid,...
userRole ( uid, rid)[align=center]==== 思想重于技巧 ====
[/align]
split_part(‘3;6;7;15;35;99;', ';', 2) = 6;
...
[/align]
其实还有个表字段包含所有ID,
问题重新描叙:
一个表A,有字段ID,包含所有数字。
一个表B,有字符串IDGROUPS‘3;6;7;15;35;99;’
如何查询得到
xx
--
3
6
7
15
35
99#测试代码
DROP TABLE IF EXISTS `testa`;
CREATE TABLE `testa` (
`id` int(11) NOT NULL default '0'
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
INSERT INTO `testa` (`id`) VALUES (1);
INSERT INTO `testa` (`id`) VALUES (2);
INSERT INTO `testa` (`id`) VALUES (3);
INSERT INTO `testa` (`id`) VALUES (4);
INSERT INTO `testa` (`id`) VALUES (5);
INSERT INTO `testa` (`id`) VALUES (6);
INSERT INTO `testa` (`id`) VALUES (7);
INSERT INTO `testa` (`id`) VALUES (8);
INSERT INTO `testa` (`id`) VALUES (9);
INSERT INTO `testa` (`id`) VALUES (10);
INSERT INTO `testa` (`id`) VALUES (11);
DROP TABLE IF EXISTS `testb`;
CREATE TABLE `testb` (
`id` int(11) default NULL,
`IdGroups` varchar(100) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
INSERT INTO `testb` (`id`,`IdGroups`) VALUES (1,'5;4;7;11;9;');
#执行SQL
select a.id as xx FROM testa a where (select FIND_IN_SET(a.id,REPLACE(b.idGroups,';',',')) from testb b where b.id='1');#结果
xx
--
4
5
7
9
11 结帖/