[英]I want all retrieve all data of customer within a radius with longtude and latitude of 1 km
I'm using redash and my table looks something like this.我正在使用 redash,我的表格看起来像这样。 I'm just learning sql. This is very advanced for me.我正在学习 sql。这对我来说非常先进。 I searched many questions, no queries worked for me我搜索了很多问题,但没有任何查询对我有用
|user_id | long | lat |
|1 |31.000|26.000|
|2 |30.000|25,000|
|3 |30.003|25,007|
I need to get all the customers that used my service in this point and a radius of 1 km as well my table looks something like this one written above adding that point of user 1 is my cennter point我需要让所有在这一点上使用我的服务的客户和 1 公里的半径以及我的表看起来像上面写的那样添加用户 1 的点是我的中心点
It is hard task just because longitude 1 is the different number of kilometers on different areas(zero on pole, 111km on equator).这是一项艰巨的任务,因为经度 1 是不同地区的不同公里数(极点为零,赤道为 111 公里)。
So most likely you have first filter your data using some values in the range for your country, after that use some specialized library to calculate the exact distance.因此,很可能您首先使用您所在国家/地区范围内的一些值来过滤数据,然后使用一些专门的库来计算确切的距离。
If you have exact point before search, you have to如果你在搜索之前有确切的点,你必须
you can use spatial functions你可以使用空间函数
SELECT
ppl.user_id,
ST_DISTANCE_SPHERE(POINT(31.000, 26.000),
POINT(ppl.Long, ppl.Lat)) AS distance
FROM
`mtytable` AS ppl
WHERE
user_id > 1
HAVING distance < 1000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.