【问题标题】:MySQL: select surname ONLY from the column with name and surnameMySQL:仅从具有名称和姓氏的列中选择姓氏
【发布时间】:2020-10-06 10:04:19
【问题描述】:

我在CUSTOMER 表中有一个包含客户姓名和姓氏的列。

11 | John Doe
12 | Kate Sanchez 
13 | Amy Lee

目的是只选择要在列中显示的id-s和名称,如:

11 | Doe
12 | Sanchez 
13 | Lee

名称的长度不同,所以我不能使用 SUBSTRING。

【问题讨论】:

  • SUBSTRING_INDEX(column, ' ', -1)
  • 像“Edward de Souza”这样的名字怎么样?
  • 幸运的是,在这个任务中我没有这样的名字,也不能数他们
  • 那你就有答案了。

标签: mysql sql string select


【解决方案1】:

你想要substring_index()吗?

select id, substring_index(name, ' ', -1) last_name
from customer

这会选择最后一个空格之后的字符串部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    相关资源
    最近更新 更多