当前位置:网站首页>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 ASCThe result of the query :

边栏推荐
- Odoo13 build a hospital HRP environment (detailed steps)
- 归并排序详解及应用
- 首批 | 腾讯云完成国内首个云原生安全成熟度评估
- [leetcode] there are duplicate elements [217]
- 數據分析學習記錄--用EXCEL完成簡單的單因素方差分析
- Qt QProgressBar详解
- Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
- [LeetCode] 存在重复元素【217】
- 世界环境日 | 周大福用心服务推动减碳环保
- 全面解析分享购商业模式逻辑?分享购是如何赋能企业
猜你喜欢

Go language sqlx library operation SQLite3 database addition, deletion, modification and query

P1007 独木桥
![[NPUCTF2020]ezlogin xPATH注入](/img/6e/dac4dfa0970829775084bada740542.png)
[NPUCTF2020]ezlogin xPATH注入

海思3559万能平台搭建:在截获的YUV图像上画框

Lambda表达式:一篇文章带你通透

Data analysis learning records -- complete a simple one-way ANOVA with Excel

Lambda expression: an article takes you through
![[Solved] Splunk: Cannot get username when all users are selected“](/img/13/1e824c8005701e21fc5b4e73308d53.png)
[Solved] Splunk: Cannot get username when all users are selected“

Qt QScrollArea

Jatpack------LiveData
随机推荐
Zhong Xuegao responded that the product will not melt for 1 hour: it contains solid components and cannot melt into water
损失函数~
静态文件显示问题
[chestnut sugar GIS] ArcScene - how to make elevation map with height
最小生成树 Minimum Spanning Tree
Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association
数组进阶提高
Wait to solve the zombie process
Learning records of data analysis (II) -- simple use of response surface method and design expert
AES高级加密协议的动机阐述
Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
【喜欢的诗词】好了歌
LC173. 二叉搜索树迭代器
Golang面试整理 三 简历如何书写
MySQL reset password, forget password, reset root password, reset MySQL password
Chow-Liu Tree
`${}`的用法
Golang's learning route
Data analysis learning records -- complete a simple one-way ANOVA with Excel
Go 4 modes Singleton