Split value from one field to two

前端 未结 14 2128
面向向阳花
面向向阳花 2020-11-22 03:49

I\'ve got a table field membername which contains both the last name and the first name of users. Is it possible to split those into 2 fields memberfirst<

相关标签:
14条回答
  • 2020-11-22 04:24

    Not exactly answering the question, but faced with the same problem I ended up doing this:

    UPDATE people_exit SET last_name = SUBSTRING_INDEX(fullname,' ',-1)
    UPDATE people_exit SET middle_name = TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(fullname,last_name,1),' ',-2))
    UPDATE people_exit SET middle_name = '' WHERE CHAR_LENGTH(middle_name)>3 
    UPDATE people_exit SET first_name = SUBSTRING_INDEX(fullname,concat(middle_name,' ',last_name),1)
    UPDATE people_exit SET first_name = middle_name WHERE first_name = ''
    UPDATE people_exit SET middle_name = '' WHERE first_name = middle_name
    
    0 讨论(0)
  • 2020-11-22 04:27

    use this

    SELECT SUBSTRING_INDEX(SUBSTRING_INDEX( `membername` , ' ', 2 ),' ',1) AS b, 
    SUBSTRING_INDEX(SUBSTRING_INDEX( `membername` , ' ', -1 ),' ',2) AS c FROM `users` WHERE `userid`='1'
    
    0 讨论(0)
提交回复
热议问题