List:General Discussion« Previous MessageNext Message »
From:Oliver Nightingale Date:June 27 2008 5:04pm
Subject:Strange Order on Calculation Field
View as plain text  
Hi,

I'm having difficulty with ordering on a calculated field, the order  
is just not doing what I expect.  I'll post the query here, it is a  
distance calculation based on lat and lng so it quite complex....

SELECT * , (
ACOS( LEAST( 1, COS( 0.898348891269513 ) * COS( -  
0.00293599286770486 ) * COS( RADIANS( stations.lat ) ) * COS( RADIANS 
( stations.lng ) ) + COS( 0.898348891269513 ) * SIN( -  
0.00293599286770486 ) * COS( RADIANS( stations.lat ) ) * SIN( RADIANS 
( stations.lng ) ) + SIN( 0.898348891269513 ) * SIN( RADIANS 
( stations.lat ) ) ) ) * 3963.19
) AS distance
FROM stations
ORDER BY `distance` ASC
LIMIT 0 , 30

So basically distance is calculated then I just want to order on  
this, however this is what I get out....

distance
9.6201
5.1337
12.508
3.5312
2.3165

So I'm confused, what strange kind of ordering is that?

Any help much appreciated,

Oliver
Thread
Strange Order on Calculation FieldOliver Nightingale27 Jun