How to split the name string in mysql?

后端 未结 16 2267
轮回少年
轮回少年 2020-11-22 11:44

How to split the name string in mysql ?

E.g.:

name
-----
Sachin ramesh tendulkar
Rahul dravid

Split the name like firstname

16条回答
  •  梦谈多话
    2020-11-22 11:48

    To get the rest of the string after the second instance of the space delimiter

    SELECT
       SUBSTRING_INDEX(SUBSTRING_INDEX('Sachin ramesh tendulkar', ' ', 1), ' ', -1) AS first_name, 
           SUBSTRING_INDEX(SUBSTRING_INDEX('Sachin ramesh tendulkar', ' ', 2), ' ', -1) 
               AS middle_name,
       SUBSTRING('Sachin ramesh tendulkar',LENGTH(SUBSTRING_INDEX('Sachin ramesh tendulkar', ' ', 2))+1) AS last_name
    

提交回复
热议问题