我目前正在使用MySql 5.7处理geo point。 我目前的要求是:
SELECT pA.id as pa, pB.id as pb, ST_Distance(pA.geo, pB.geo) as distance
FROM point_A pA
JOIN point_B pB
ORDER BY pa, distance
示例输出:
+-------+-------+---------------------+
| pa | pb | distance |
+-------+-------+---------------------+
| 1 | 5535 | 0.23752813469351355 |
| 1 | 5536 | 0.8110224552241297 |
| 1 | 5533 | 0.8359718468573036 |
| 2 | 5536 | 0.8763100264270072 |
| 2 | 5536 | 0.0665454376162462 |
| 2 | 5533 | 1.0669544991122402 |
| 3 | 5533 | 0.2469039758259646 |
| 3 | 5536 | 0.329452951307464 |
| 3 | 5533 | 1.3593527448933072 |
我只希望每个pa首次出现。如果不使用子请求和第二次ST_Distance(性能成本),我找不到这样做的方法
预期结果:
+-------+-------+---------------------+
| pa | pb | distance |
+-------+-------+---------------------+
| 1 | 5535 | 0.23752813469351355 |
| 2 | 5536 | 0.8763100264270072 |
| 3 | 5533 | 0.2469039758259646 |
我已经尝试过group by和distinct,但我的所有距离值都是唯一的pa,pb。