mysql连接提取数

mysql连接提取数,mysql,regex,join,Mysql,Regex,Join,我有一张像这样的大桌子 id user type comment 6 1 A id '3' - #8 7 1 A id '3' - #9 8 3 B 9 3 B 我想提取散列后的数字,并将其与id列连接,以获得以下内容(当单引号之间的数字等于用户时) A创建表的副本,其名称为bigtable,并插入您提供给我们的值: mysql> create table bigtable (id

我有一张像这样的大桌子

    id  user type comment
    6   1    A    id '3' - #8
    7   1    A    id '3' - #9
    8   3    B    
    9   3    B  
我想提取散列后的数字,并将其与id列连接,以获得以下内容(当单引号之间的数字等于用户时)


A创建表的副本,其名称为bigtable,并插入您提供给我们的值:

mysql> create table bigtable (id int, user_id int, type varchar(10), comment varchar(30));
Query OK, 0 rows affected (0.04 sec)

mysql> insert into bigtable values (6,1, 'A', 'id 3 - #8'),(7,1,'A', 'id 3 - #9'),(8,3, 'B','' ),(9,3, 'B','');
Query OK, 4 rows affected (0.01 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> select * from bigtable;
+------+---------+------+-----------+
| id   | user_id | type | comment   |
+------+---------+------+-----------+
|    6 |       1 | A    | id 3 - #8 |
|    7 |       1 | A    | id 3 - #9 |
|    8 |       3 | B    |           |
|    9 |       3 | B    |           |
+------+---------+------+-----------+
4 rows in set (0.00 sec)
我做了一个自连接并使用了substrn_索引函数:

mysql> select b1.id,b2.id,b1.user_id,b1.type 
from bigtable as b1 join bigtable as b2 
on b1.id=SUBSTRING_INDEX(b2.COMMENT,'#',-1);
+------+------+---------+------+
| id   | id   | user_id | type |
+------+------+---------+------+
|    8 |    6 |       3 | B    |
|    9 |    7 |       3 | B    |
+------+------+---------+------+
2 rows in set (0.00 sec)

我希望这对您有所帮助

有什么共同点吗?你能把表的结构吗?id和用户(INT11),类型和注释(VARCHAR55)
mysql> select b1.id,b2.id,b1.user_id,b1.type 
from bigtable as b1 join bigtable as b2 
on b1.id=SUBSTRING_INDEX(b2.COMMENT,'#',-1);
+------+------+---------+------+
| id   | id   | user_id | type |
+------+------+---------+------+
|    8 |    6 |       3 | B    |
|    9 |    7 |       3 | B    |
+------+------+---------+------+
2 rows in set (0.00 sec)