Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要对列的部分值进行排序。
例如,我有一个包含列(代码、名称)的表员工。Code列值的格式为DEPT:SR_NO。
我只需要对 Code 列的 SR_NO 值进行排序。
上述场景只是实时场景的示例。
任何建议将不胜感激。
谢谢,
SELECT SUBSTRING_INDEX(code, ':', 1) AS dept SUBSTRING_INDEX(code, ':', -1) AS sr_no FROM mytable ORDER BY sr_no
正则表达式,是的。您还可以执行类似Order by Right(Name, Len(Name)-Instr(Name, ":"))的操作,例如提取冒号右侧的所有字符并按此排序。
Order by Right(Name, Len(Name)-Instr(Name, ":"))