How to split the name string in mysql?

后端 未结 16 2266
轮回少年
轮回少年 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 12:02

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

    SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(MsgRest, ' ', 1), ' ', -1) AS EMailID
    ,  SUBSTRING_INDEX(SUBSTRING_INDEX(MsgRest, ' ', 2), ' ', -1) AS DOB
    ,  IF(
        LOCATE(' ', `MsgRest`) > 0,
        TRIM(SUBSTRING(SUBSTRING(`MsgRest`, LOCATE(' ', `MsgRest`) +1), 
             LOCATE(' ', SUBSTRING(`MsgRest`, LOCATE(' ', `MsgRest`) +1)) +1)),
        NULL
    ) AS Person
    FROM inbox
    

提交回复
热议问题