2

我有这个查询:

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 列,但同时按公式对其进行排序,以便我可以轻松使用hibernate。

我不想在选择结果表中有“结果”新列。

我怎样才能在 MySQL 中做到这一点?

4

1 回答 1

4

将您的查询包装在另一个查询中

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
于 2013-11-05T10:55:40.283 回答