相关疑难解决方法(0)

为什么这种递归连接会产生:数据太长

我在 MySQL 8 上有这个表:

create table tbl(id varchar(2), val int);
insert into tbl values ('A',  1), ('B',  2), ('C',  3), ('D',  4), ('E',  5);
Run Code Online (Sandbox Code Playgroud)

以下查询应找出哪些记录集的值加起来不大于 6(不考虑顺序):

with recursive cte(greatest_id, ids, total) as (
    select     id,
               concat(id, ''), 
               val
    from       tbl
    union all
    select     tbl.id,
               concat(cte.ids, tbl.id),
               cte.total + tbl.val
    from       cte 
    inner join tbl 
            on tbl.id > cte.greatest_id
           and cte.total + tbl.val <= 6
) 
select ids, total from cte
Run Code Online (Sandbox Code Playgroud)

运行它会导致以下错误:

错误:ER_DATA_TOO_LONG:concat(id, '')第 7行列的数据太长

为什么 MySQL 会产生这个错误? …

mysql varchar concat recursive-query

1
推荐指数
1
解决办法
1265
查看次数

标签 统计

concat ×1

mysql ×1

recursive-query ×1

varchar ×1