Split value from one field to two

前端 未结 14 2134
面向向阳花
面向向阳花 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:01

    Method I used to split first_name into first_name and last_name when the data arrived all in the first_name field. This will put only the last word in the last name field, so "john phillips sousa" will be "john phillips" first name and "sousa" last name. It also avoids overwriting any records that have been fixed already.

    set last_name=trim(SUBSTRING_INDEX(first_name, ' ', -1)), first_name=trim(SUBSTRING(first_name,1,length(first_name) - length(SUBSTRING_INDEX(first_name, ' ', -1)))) where list_id='$List_ID' and length(first_name)>0 and length(trim(last_name))=0
    

提交回复
热议问题