【发布时间】:2021-06-30 06:01:43
【问题描述】:
CREATE TABLE tablename (id INT,C1 text);
INSERT INTO tablename VALUES
(1, '[AU 1] string 1; [AU 2] string 2; [AU 3] string 3.1; string 3.2; [AU 4] string 4.1; string 4.2; [AU 5] string 5'),
(2, '[AU 1; AU 2] string 1'),
(3, '[AU 1] string 1; [AU 2] string 2');
CREATE TABLE numbers (n INT PRIMARY KEY);
INSERT INTO numbers VALUES (1),(2),(3),(4),(5),(6);
按照“@fthiella”和“@RGarcia”的例子,我已经很接近了。
请看小提琴here。
我得到的结果与“我想要这样的输出”中的预期不同:
我想要这样的输出
| ID | AU | ORG |
| 1 |[AU 1]|string_1|
| 1 |[AU 2]|string_2|
| 1 |[AU 3]|string_3.1|
| 1 |[AU 3]|string_3.2|
| 1 |[AU 4]|string_4.1|
| 1 |[AU 4]|string_4.2|
| 1 |[AU 5]|string_5|
| 2 |[AU 1; AU 2]|string_1|
| 3 |[AU 1]|string_1|
| 3 |[AU 2]|string_2|
【问题讨论】:
-
首先stackoverflow.com/questions/3653462/…不要将数据存储在分隔符列中,分号也是您不能以这种方式使用它的分隔符。如果你真的想要这样的分隔列,最后使用 json
-
@nbk,感谢您的建议,但基础在 jason 中不可用,并且转换它需要更多的工作
-
你应该切换到一个存储过程或函数,这需要一些努力,因为你有不同容量的相同分隔符
-
@Akina,10.4.17-MariaDB。
-
@Akina,非常感谢,就是这样!
标签: mysql substring mariadb-10.4