mysql截取字符全去匹配第二张表..急。100分。。
在第一张表里取得 :authority列所对应的值 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18
第二张表结构: id int 对应第一张表取到的值(varchar类型), name varchar(20)
现在要要写sql 得到所有name值
用mysql实现, 求救。。。。。。。。。。。。。。。
[解决办法]
贴建表及插入记录的SQL,及要求结果出来看看
try:
select * from b1 inner join b2 on find_in_set(id,authority)>0
[解决办法]
- SQL code
mysql> use test;Database changedmysql> create table t1(authority varchar(20));Query OK, 0 rows affected (0.42 sec)mysql> create table t2( id int ,name varchar(20));Query OK, 0 rows affected (0.32 sec)mysql> insert into t1 values(1),(2),(3);Query OK, 3 rows affected (0.31 sec)Records: 3 Duplicates: 0 Warnings: 0mysql> insert into t2 values(1,"zhangsan"),(2,"lisi"),(3,"wangwu");Query OK, 3 rows affected (0.30 sec)Records: 3 Duplicates: 0 Warnings: 0mysql> select * from t2 where id in (select authority from t1);+------+----------+| id | name |+------+----------+| 1 | zhangsan || 2 | lisi || 3 | wangwu |+------+----------+3 rows in set (0.03 sec)
[解决办法]
select *
from 第二张表
where id in (select authority from 第一张表)
[解决办法]
贴建表及插入记录的SQL,及要求结果出来看看
SELECT A.* FROM B1 A INNER JOIN B2 B ON A.ID=B.authority
[解决办法]
select *
from table2
where id in (select authority from table1)
[解决办法]
每次来做问答,发现我心中的答案总被一个狼头或者一个苹果上的企鹅说出来了
[解决办法]
select *
from table2
where id in (select authority from table1)
这个就可以的呀
[解决办法]
select * from db_groupuser a inner join db_authority b on find_in_set(b.id,a.authority)>0
这个不行?要求什么结果?