当前位置:网站首页>MySQL查询附近的数据.并按距离进行排序.
MySQL查询附近的数据.并按距离进行排序.
2022-07-02 22:09:00 【会飞的哈士奇】
业务背景:
查看我附近的公共厕所, 查询的时候通过传入当前使用人的经度(lng)与纬度(lat), 与数据库里的厕所信息进行位置计算, 得出我距离每个厕所的距离(单位:公里), 并且按照距离的远近进行排序, 最近的显示在最上面
SELECT
t1.name,
t1.address,
t1.uid,
t1.code
CONVERT(ACOS(COS(${lat}*PI()/180 )*COS(t1.lat*PI()/180)*COS(${lng}*PI()/180-t1.lng*PI()/180)+SIN(${lat}*PI()/180 )*SIN(t1.lat*PI()/180))*6370996.81/1000, DECIMAL(10,2)) AS distance
FROM
toilet t1
WHERE
t1.is_delete = '0'
ORDER BY
distance ASC查询后的结果:

边栏推荐
- 数据库系统概论第一章简答题-期末考得怎么样?
- 《乔布斯传》英文原著重点词汇笔记(十一)【 chapter nine】
- Utilisation de simpletk - 4. Question étrange
- 【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
- 《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
- boot actuator - prometheus使用
- Server response status code
- U++ 学习笔记 ----松弛
- Niuke: Dragon and dungeon games
- [LeetCode] 回文数【9】
猜你喜欢
随机推荐
UE4 UI adaptive screen
杰理之如何测试按键的误触率【篇】
NC24325 [USACO 2012 Mar S]Flowerpot
Il n'est pas nécessaire d'appuyer longtemps sur la fonction de démarrage pour modifier Jelly [chapitre]
P7072 [CSP-J2020] 直播获奖
Array advanced improvement
#include errors detected. Please update your includePath.
傑理之修改不需要長按開機功能【篇】
Jatpack------LiveData
php优化foreach中的sql查询
杰理之直接触摸样机的顶针反应不正常【篇】
Higher order operation of bits
《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
Film and television excerpts
全面解析分享购商业模式逻辑?分享购是如何赋能企业
PMP项目整合管理
Source code analysis - lightweight asynchronous crawler framework Ruia
Jatpack------LiveData
Go condition variable
Baidu AI Cloud - create a face recognition application




![[LeetCode] 反转字符串中的单词 III【557】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)




