我有这个查询:
SELECT locations.id, 1609.34 * 3956 * 2 * ASIN( SQRT( POWER( SIN( (55.170000 - abs(locations.latitude)) * pi() / 180 / 2), 2) + COS(55.170000 * pi() / 180 ) * COS(abs (locations.latitude) * pi() / 180) * POWER(SIN((-7.400000 - (locations.longitude)) * pi() / 180 / 2), 2) ) ) as result FROM locations order by result asc limit 10;
我想要的只是获取locations.id列,但同时按公式对其进行排序,这样我就可以轻松使用休眠方式。
我不想在选择结果表中包含“结果”新列。
如何在MySQL中做到这一点?
将您的查询换成另一个查询
SELECT Location FROM ( SELECT locations.id as Location, 1609.34 * 3956 * 2 * ASIN( SQRT( POWER( SIN( (55.170000 - abs(locations.latitude)) * pi() / 180 / 2), 2) + COS(55.170000 * pi() / 180 ) * COS(abs (locations.latitude) * pi() / 180) * POWER(SIN((-7.400000 - (locations.longitude)) * pi() / 180 / 2), 2) ) ) as result FROM locations order by result asc limit 10 ) AS L