티스토리 뷰
SELECT *,
SQRT( POW( ( (69.1/1.61) * ('37.5333131' - A.centerLat)), 2)
+ POW(( (53/1.61) * ('127.0862168' - A.centerLng)), 2)) AS distance
FROM (
select max(centerLat) as centerLat, max(centerLng) as centerLng
from rectId
group by groupIdx
) A
WHERE centerLat > '37.5333131' - 10 / (69.1/1.61)
AND centerlat < '37.5333131' + 10 / (69.1/1.61)
AND centerLng > '127.0862168' - 10 / (53/1.61)
AND centerlng < '127.0862168' + 10 / (53/1.61)
HAVING distance < 3
order by distance asc
SELECT *,
ROUND( SQRT( POW( ( (69.1/1.61) * ('52.64' - latitude)), 2) +
POW(( (53/1.61) * ('6.88' - longitude)), 2)), 1) AS distance
FROM lp_relations_addresses
WHERE latitude > '52.64' - 10 / (69.1/1.61)
AND latitude < '52.64' + 10 / (69.1/1.61)
AND longitude > '6.88' - 10 / (53/1.61)
AND longitude < '6.88' + 10 / (53/1.61)
HAVING distance < 10
ORDER BY distance DESC
-- 37.5333131,127.0862168,14.65z
널린게 쿼리이다.
stackoverflow.com/questions/41081165/sql-search-near-longitude-and-latitude
'프로그래밍 > DB' 카테고리의 다른 글
mysql Lock 걸린 task 죽이는 방법 (0) | 2021.11.29 |
---|---|
테이블 위치 찾는 쿼리 (0) | 2021.02.04 |
mssql 쿼리명세서 생성 (0) | 2020.11.16 |
mssql에서 컬럼왼쪽에 0으로 채워야 할때 (0) | 2020.11.06 |
mssql에서 duplucate on 변환방법 (0) | 2020.09.24 |