我有tbl,它包括两列:title和params,值如下:
题目:
{“教学”}
参数:
{“ufield926”:“34”,
“ufield927”:“sud”,
“ufield928”:“ara”,
“ufield929”:“麦加”,
“ufield930”:“1983年1月1日”,
“ufield933”:“011”,
“ufield934”:“mub”,
“ufield943”:“su/hi/14”,
“ufield944”:“平均”,
“ufield946”:“女性”
}
我想提取“ufield943”之后的代码:它仅是su/hi/14,并将其与title列中的值连接起来,如下所示:
-->教学(SU/HI/14)
以下是我尝试过的查询:

SELECT CONCAT(title, "(", (select
       substring(
         params,
         locate('ufield943', params) + 12,
         locate('ufield944', params) - locate('ufield943', params) - 21
       ) FROM tbl), ")") AS title
FROM tbl;

每次运行查询时都会出现以下错误
“35; 1242-子查询返回多行”

最佳答案

我将{"..."}SUBSTRING函数一起从标题中删除CHAR_LENGTH
我将- 21改为- 16并在(之前添加空格

SELECT CONCAT(substring(title, 3,CHAR_LENGTH(title) - 4 ), " (",
   substring(
     params,
     locate('ufield943', params) + 12,
     locate('ufield944', params) - locate('ufield943', params) - 16
   ), ")") AS Title
FROM tbl;

DEMO

关于mysql - MySQL - (#1242)子查询返回超过1行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56866849/

10-13 08:57