Sorting decimal numbers stored in varchar column
Dear all,
i am using MySQL 5.1 on windows 7.
i want to sort the numbers properly. i have the following structure.
create table num (a varchar(1));
insert into num values ('1');
insert into num values('1.1');
insert into num values('1.1.1');
insert into num values('1.1.2');
insert into num values('1.2');
insert into num values('1.3');
insert into num values('1.4');
insert into num values('1.5');
insert into num values('1.6');
insert into num values('1.7');
insert into num values('1.8');
insert into num values('1.9');
insert into num values('1.10');
insert into num values('2');
insert into num values('2.1');
commit;
i know how to do it in oracle, in oracle i issue the below query and it works fine,
SELECT * FROM num
ORDER BY to_number(regexp_substr(a, '[^.]+', 1, 1)) NULLS FIRST,
to_number(regexp_substr(a, '[^.]+', 1, 2)) NULLS FIRST,
to_number(regexp_substr(a, '[^.]+', 1, 3)) NULLS FIRST;
the result is below
1
1.1
1.1.1
1.1.2
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
1.10
2
2.1
how to get this sorting in mysql?
THank you
Subject
Written By
Posted
Sorting decimal numbers stored in varchar column
May 20, 2015 11:53PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.