MySQL Query Building和地理点

时间:2016-03-07 09:50:36

标签: mysql

我有称为广告的MySQL表,每个广告都有一个独特的id和地理点字段location

我现在正在做的是计算特定点POINT(46.52167 23.81167)附近的广告数量,并使用此SQL查询正常工作

SELECT 
    COUNT(*) AS count,
    MAX(ST_DISTANCE(GEOMFROMTEXT('POINT(46.52167 23.81167)'),
            location)) AS radius
FROM
    ads
WHERE
    ST_DISTANCE(GEOMFROMTEXT('POINT(46.52167 23.81167)'),
            location) < 0.17536759746391475;

有时我对请求有20分或更多,我想为所有这些查询运行,这需要花费很多时间,因为我将多个查询组合在一起。

例如我有两个点POINT(46.52167 23.81167)POINT(46.72417 23.51167)我使用以下SQL

SELECT 
    COUNT(*) AS count,
    MAX(ST_DISTANCE(GEOMFROMTEXT('POINT(46.52167 23.81167)'),
            location)) AS radius
FROM
    ads
WHERE
    ST_DISTANCE(GEOMFROMTEXT('POINT(46.52167 23.81167)'),
            location) < 0.17536759746391475;
SELECT 
    COUNT(*) AS count,
    MAX(ST_DISTANCE(GEOMFROMTEXT('POINT(46.72417 23.51167)'),
            location)) AS radius
FROM
    ads
WHERE
    ST_DISTANCE(GEOMFROMTEXT('POINT(46.72417 23.51167)'),
            location) < 0.17536759746391475;

我的问题:有没有办法优化并将这两个查询合并为一个?使用分组或具有或任何方法或算法?

0 个答案:

没有答案