简体   繁体   English

MySQL如何在全名字段上按姓氏排序?

[英]MySQL How to order by last name on a full name field?

I have a SQL table with a column called full name which contains "John Doe" 我有一个SQL表,其中有一列称为全名,其中包含“ John Doe”

How can order the data by the last name that appears in the full name column ? 如何按全名栏中显示的姓氏对数据进行排序?

For a long name like "John Doe Second", I would like to order the data by the word "Doe". 对于像“ John Doe Second”这样的长名称,我想通过单词“ Doe”对数据进行排序。

I am using MySQL database. 我正在使用MySQL数据库。

EDIT: Here is the precision : Case "John" is impossible. 编辑:这是精度:情况下“约翰”是不可能的。 What I consider as the last name should be after the FIRST space in my string. 我认为的姓氏应该在字符串的第一个空格之后。

这应该工作:

SELECT * FROM some_table ORDER BY SUBSTR(Name, INSTR(Name, ' '))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM