So erhalten Sie den Vornamen aus der Spalte „customer_name'.
P粉908643611
P粉908643611 2024-04-06 17:43:30
0
2
599
select substring(custmer_name, 1, instr(custmer_name, ' ')) as first_name from sales.customers;

Diese Lösung hat mir die Antwort gegeben, funktioniert aber nicht für den Nachnamen

P粉908643611
P粉908643611

Antworte allen(2)
P粉884548619

使用SUBSTRING_INDEX()需要3个参数:

  1. 列名称
  2. Delimiter
  3. 出现次数

您可以在此找到更多说明文章

查询

SELECT
  SUBSTRING_INDEX(customer_name,' ', 1) as first_name, 
  SUBSTRING_INDEX(customer_name,' ', -1) as last_name FROM customer;
P粉276064178

请测试一下:我使用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;

结果集:

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage