mysql - 如何在MySQL中按混合字符串/整数列的升序排序?

标签 mysql select

我有这样的 table

------------------------
Id  |  MergeId  | name |
------------------------
1   |   M1      | Riya |
2   |   M2      | diya |
3   |   M3      | tiya |
------------------------

现在我需要选择表 OrderBy Ascending MergeId (M1,M2,M3,M4.....)

最佳答案

您需要删除M,然后将值转换为数字。您可以使用数学运算来隐式执行此操作

select * from your_table
order by substring(mergeId, 2) * 1 asc

或者明确地使用

order by cast(substring(mergeId, 2) as unsigned) asc

关于mysql - 如何在MySQL中按混合字符串/整数列的升序排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25128289/

相关文章:

mysql - "unconcatenating"字段和旋转 mysql 或 talend

mysql - 从 MySQL 的列中删除 h1 文本

mysql - "... Where field ON (SELECT ..)"不能与工作 where 子句中的 "select"一起使用

sql - MySQL:使用 IN 和 ORDER BY 时避免文件排序

mysql - 从列中获取非日期时间字符串值

arrays - 算法 - 如何从数组中的每一列中选择一个数字,以便它们的总和尽可能接近特定值

mysql - 如何在其中一列中选择具有特定数字的行?

连接两个表时的Mysql Distinct max列

SQLite 与内部选择

php - PHP 表中的换行符