源数据:
结果:
希望的结果: 类似于结果的样子,但如果没有爹就在他爹这行显示自己的名字
但有id=2的时候的数据的时候就出现subquery returns more than 1 row
执行的sql是
select f.id,(select fa.title from familly fa where locate(f.id,fa.childStories)>0 ) '他爹',f.title as '名字',f.childStories from familly f;
...全文
1743打赏收藏
求助这sql是什么问题
源数据: 结果: 希望的结果: 类似于结果的样子,但如果没有爹就在他爹这行显示自己的名字 但有id=2的时候的数据的时候就出现subquery returns more than 1 row 执行的sql是 select f.id,(select fa.title from familly fa where locate(f.id,fa.childStories)>0 ) '他爹',f.title as '名字',f.childStories from familly f;
select f.id,(select group_concat(fa.title) from familly fa where locate(f.id,fa.childStories)>0 ) '他爹',f.title as '名字',f.childStories from familly f;
这样可以把所有的他爹写在一起,也不会报错了