当前位置:网站首页>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 :

边栏推荐
- 地方经销商玩转社区团购模式,百万运营分享
- 最小生成树 Minimum Spanning Tree
- Motivation du Protocole de chiffrement avancé AES
- [羊城杯2020]easyphp
- Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
- WebRTC音视频采集和播放示例及MediaStream媒体流解析
- Higher order operation of bits
- Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
- 手写ORM(对象关系映射)增删改查
- JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
猜你喜欢

地平线2022年4月最新方案介绍

P1007 独木桥

数据分析学习记录--用EXCEL完成简单的单因素方差分析

xshell配置xforward转发火狐浏览器

boot actuator - prometheus使用

Jatpack------LiveData

Odoo13 build a hospital HRP environment (detailed steps)

Go语言sqlx库操作SQLite3数据库增删改查

Addition, deletion, modification and query of handwritten ORM (object relationship mapping)

海思3559万能平台搭建:在截获的YUV图像上画框
随机推荐
P7072 [CSP-J2020] 直播获奖
Niuke network: maximum submatrix
Golang interview finishing three resumes how to write
Qt QProgressBar详解
go 4种单例模式
Learning Websites commonly used by circuit designers
编辑卡顿
Boot actuator - Prometheus use
Go 4 modes Singleton
[羊城杯2020]easyphp
[leetcode] there are duplicate elements [217]
1px pixel compatibility of mobile terminal, 1px border
[Luogu p1541] tortoise chess [DP]
The motivation of AES Advanced Encryption Protocol
性能优化----严苛模式
Go language sqlx library operation SQLite3 database addition, deletion, modification and query
MySQL查询附近的数据.并按距离进行排序.
[LeetCode] 存在重复元素【217】
Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association
QT qsplitter splitter