[英]How to get numeric values from alpha numeric using SQL query and sort by the numeric
In MySQL DB 在MySQL DB中
Colum1
Drill 14"
Drill 15"
Drill 10"
Drill 11"
Drill 5"
I want to get the numerical values and sort it like so 我想获得数值并将其排序
Colum1
5
10
11
14
15
Note that i don't want to use declare because it does not accepted by the Jasper - so if there is simple SQL that can do it should be fine 请注意,我不想使用声明,因为它不被Jasper接受 - 所以如果有简单的SQL可以做到它应该没问题
You can use SUBSTRING_INDEX
您可以使用SUBSTRING_INDEX
ORDER BY SUBSTRING_INDEX(Colum1,' ', -1)+0 ASC
Demonstration: 示范:
SET @str := 'Drill 11';
SELECT SUBSTRING_INDEX(@str,' ',-1)+0 AS number;
Output: 输出:
number
11
Demo here: 在这里演示:
Try This 尝试这个
SELECT *
FROM Table_Name
WHERE Colum1 REGEXP '^[0-9]+$';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.