Hello. There are lines in which there can be letters as well as numbers. How to sort them only by numeric value or by letter without numbers? I read that there are functions DEPTNO and ENAME, but they do not work in MYSQL. How can I create their implementation in MYSQL?
1 answer
Try converting data types. Of course, you should take into account what values you have in the field being sorted, but sometimes it is enough to do the following:
SELECT `field_name` FROM `table_name` ORDER BY CAST( `field_name` AS SIGNED ) // или же просто SELECT `field_name` FROM `table_name` ORDER BY `field_name` + 0
|
string
, '1', '') as s1 FROMtable
) as s1) as s2) as s3 - user6550string
, '1', ''), '2', ''), '3', '') ... <etc.> as c1 FROMtable
order by c1 - msi