Re: numeric sorting on a char field having a decimal
Posted in 2006
Marco Greco said
select c from t order by warpedsort(c)
which yields when I use my test data:
select abbinormal, warpedsort(abbinormal) from decimaul order by 2;
abbinormal (expression)
7.4 4
8.4 4
7.5 5
8.5 5
7.11 11
8.11 11
7.23 23
8.23 23
8.24 24
7.24 24
7.29 29
8.29 29
7.34 34
8.34 34
8.40 40
7.40 40
8.45 45
7.45 45
Which Is not what I think he wants.
but your earlier post led me to my favorite answer.
which is
select abbinormal, abbinormal::int, length(abbinormal),abbinormal::decimal(10,5) - abbinormal::int from decimaul order by
2,3,4;
Which is to say sort them by the integer part of the number then sort
it by the length of the mantissa, if the mantissa are of the same
length sort it in mantissa order.