私信  •  关注

sumit

sumit 最近创建的主题
sumit 最近回复了
5 年前
回复了 sumit 创建的主题 » 从MySQL数据库中选择数据时遇到问题

可以使用子字符串索引修剪最后两个句点之间的字符

所以你的问题如下

select 
case when parent ='' then '-' else concat(parent,'.') end  as parent ,
userid,
name
from
(
select 
TRIM(TRAILING concat('.',substring_index(TRIM(TRAILING '.' from USERID), '.', -1),'.')  from USERID) as parent, 
NAME as name,
USERID from user
)tmp

工作小提琴 http://sqlfiddle.com/#!9/36435a/13