MySQL Forums
Forum List  »  General

Re: Sorting decimal numbers stored in varchar column
Posted by: Rick James
Date: June 04, 2015 08:51AM

The best way is to have another column that has a sanitized version of the version number. Perhaps:
1.0000.0000
1.0001.0001
etc

It should be possible to do it in an ORDER BY with
* 0+ to convert to numeric
* IFNULL instead of NULLS first and use
* MID and INSTR (see below)
* other functions from
http://dev.mysql.com/doc/refman/5.6/en/string-functions.html
* Note that

Perhaps
ORDER BY
0+MID(a, 0, LOCATE('.', a, 1)-1),
0+MID(a, LOCATE('.', a, 1)+1, LOCATE('.', a, 2)-1),
0+MID(a, LOCATE('.', a, 2)+1, LOCATE('.', a, 3)-1)

(I have not tested that, so it may need some debugging.)

Options: ReplyQuote


Subject
Written By
Posted
Re: Sorting decimal numbers stored in varchar column
June 04, 2015 08:51AM


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.