select substring(custmer_name, 1, instr(custmer_name, ' ')) as first_name from sales.customers;
这个解决方案给了我答案,但它不适用于姓氏
P粉8845486192024-04-07 16:34:04
使用SUBSTRING_INDEX()需要3个参数:
您可以在此找到更多说明文章
查询
SELECT SUBSTRING_INDEX(customer_name,' ', 1) as first_name, SUBSTRING_INDEX(customer_name,' ', -1) as last_name FROM customer;
P粉2760641782024-04-07 14:24:41
请测试一下:我使用locate函数来定义“ ”的位置。
SELECT LEFT(customer_name, LOCATE(' ',customer_name)-1) as first_name, RIGHT(customer_name, LENGTH(customer_name)-LOCATE(' ',customer_name)) as last_name FROM customer;