I am trying to get the decimal numbers to order correctly.
Here is my code:
$sql = "(SELECT * FROM locations WHERE X REGEXP '^[0-9]' ORDER BY cast(X as decimal), X, Y)
UNION ALL
(SELECT * FROM locations WHERE X REGEXP '^[a-z,A-Z]') ORDER BY X, Y";
Right now, numbers on top but not in correct order, Alpha on bottom is in order
1, 1.5, 10, 10.5, 18, 2, ADMIN, CAFE, CDC, CMAT
I need:
1, 1.5, 2, 10, 10.5, 18, ADMIN, CAFE, CDC, CMAT
Order by Numeric decimals then Alpha
Moderator: General Moderators
-
phpdeveloper1
- Forum Newbie
- Posts: 19
- Joined: Tue Aug 12, 2014 6:13 am
- Location: Chennai, India
Re: Order by Numeric decimals then Alpha
Have you tried giving the decimal precision and scale ?wpdfran wrote:................ cast(X as decimal), X, Y)
.................
(http://dev.mysql.com/doc/refman/5.0/en/ ... types.html)
Chris, Php Developer and Programmer,
https://www.phpfreelanceprogrammer.com/
https://www.phpfreelanceprogrammer.com/