简体   繁体   English

如何在MySQL中使用数值对列进行排序

[英]How to sort a column with numeric values in MySQL

In one of my table column I have values like: 在我的一个表格列中,我有以下值:

"fol v1.1.2",
"fol v1.2.10",
"fol v1.5.6",
"all fols",
"fol v1.7.10 updated 22.03.2019",
"fol v1.10.11"

After ordering i need the values like: 订购后我需要以下值:

"all fols",
"fol v1.1.2",
"fol v1.2.10",
"fol v1.5.6",
"fol v1.7.10 updated 22.03.2019",
"fol v1.10.11"
select * from trial order by substring_index(dat,'.',1),cast(substring_index(substring_index(dat,'.',2),'.',-1) as signed),cast(substring_index(substring_index(dat,'.',3),'.',-1) as signed);

what i did is, split the versions in by '.' 我做的是,将版本拆分为'。' as a delimiter and then convert into integers then group them according to values. 作为分隔符然后转换为整数然后根据值对它们进行分组。

for more information about splitting refer this w3resource-mysql-substring 有关拆分的更多信息,请参阅此w3resource-mysql-substring

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

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