Taking only characters from the left and right of a specific character in mySQL

五迷三道 提交于 2019-12-04 19:58:46

Besides combining LEFT() and RIGHT() with LOCATE(), you can also use SUBSTRING_INDEX():

SELECT
    SUBSTRING_INDEX(Player, '_', 1) AS FirstName
  , SUBSTRING_INDEX(Player, '_', -1) AS LastName
LEFT(Player, (LOCATE('_', Player) - 1))

You just basicly decrease the value of the second parameter in LEFT by 1 to exclude the _

Will Mayall
select distinct left(HOST,locate (':',HOST)-1) CONNECTED_HOST 
from information_schema.processlist 
where User != 'root' 
order by 1;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!