当前位置:网站首页>MySQL queries nearby data And sort by distance
MySQL queries nearby data And sort by distance
2022-07-02 23:02:00 【Flying husky】
Business background :
Check the public toilets near me , When querying, pass in the longitude of the current user (lng) And latitude (lat), Calculate the location with the toilet information in the database , Get the distance between me and each toilet ( Company : km ), And sort according to the distance , The most recent ones are displayed at the top
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
The result of the query :
边栏推荐
- 數據分析學習記錄--用EXCEL完成簡單的單因素方差分析
- 景联文科技低价策略帮助AI企业降低模型训练成本
- 地方经销商玩转社区团购模式,百万运营分享
- Uniapp wechat login returns user name and Avatar
- PMP project integration management
- Jericho's thimble reaction when directly touching the prototype is abnormal [chapter]
- Learning Websites commonly used by circuit designers
- E-commerce system microservice architecture
- AES高級加密協議的動機闡述
- Qt QScrollArea
猜你喜欢
情感对话识别与生成简述
性能优化----严苛模式
[LeetCode] 数组中的第K个最大元素【215】
【硬件】标准阻值的由来
Hanging mirror security won four global infosec awards on rsac2022
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
从2022年Q1财报看携程的韧性和远景
[leetcode] most elements [169]
全面解析分享购商业模式逻辑?分享购是如何赋能企业
Lambda expression: an article takes you through
随机推荐
Uniapp wechat login returns user name and Avatar
Local dealers play the community group purchase mode and share millions of operations
AES高級加密協議的動機闡述
To myself who is about to work
Jericho's thimble reaction when directly touching the prototype is abnormal [chapter]
P7072 [csp-j2020] live broadcast Award
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
[NPUCTF2020]ezlogin xPATH注入
go 4种单例模式
How does Jerry test the wrong touch rate of keys [chapter]
Storage unit conversion
The motivation of AES Advanced Encryption Protocol
Zhong Xuegao responded that the product will not melt for 1 hour: it contains solid components and cannot melt into water
景联文科技低价策略帮助AI企业降低模型训练成本
Jerry's built-in short press and long press, no matter how long it is, it is a short press [chapter]
[Luogu p1541] tortoise chess [DP]
[leetcode] most elements [169]
高并发介绍及应对
P7072 [CSP-J2020] 直播获奖
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?