一个字符串‘3;6;7;15;35;99;’
如何查询得到
xx
--
3
6
7
15
35
99
如何查询得到
xx
--
3
6
7
15
35
99
解决方案 »
- mysql 多表随机查询语句的写法【help】
- 感谢大家啊~但是按照大家的办法我100w的数据,运行了15个小时还没出结果。所以麻烦大家在看看啊~
- MySQL安装不了,大家帮忙看看是什么问题
- 各位在数据量增大的时候用什么技术改进的呢?
- 求一查询语句
- mysql数据库怎样查询任意一个月的数据
- MYSQL存储过程的输出参数可以是游标吗?
- mysql5.0存储过程问题
- select的联表子查询的问题。(实用)
- 怎么mysql 5 在用命令describe tables,就出错,然后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 结帖/