您好,登錄后才能下訂單哦!
環(huán)境
MySQL5.6
https://dev.mysql.com/doc/refman/5.6/en/spatial-relation-functions-object-shapes.html#function_st-distance
表結(jié)構(gòu)及數(shù)據(jù)
DROP TABLE IF EXISTS `locationpoint`; CREATE TABLE `locationpoint` ( `id` int(11) NOT NULL AUTO_INCREMENT, `province` varchar(20) NOT NULL, `city` varchar(20) NOT NULL, `longitude` double(10, 3) NOT NULL, `latitude` double(10, 3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE = InnoDB AUTO_INCREMENT = 1156 DEFAULT CHARSET = utf8;
INSERT INTO `locationpoint` VALUES (1, '山東', '濟(jì)南', 116.938477, 36.597889), (2, '河北', '石家莊', 114.477539, 38.030786), (3, '浙江', '杭州', 120.058594, 30.334954), (4, '河南', '鄭州', 113.629, 34.744), (5, '安徽省', '合肥', 117.170, 31.520);
查詢方式
(以內(nèi)蒙古自治區(qū)呼和浩特市為計(jì)算中心)
SELECT id, city, longitude, latitude, round( ( st_distance( point(longitude, latitude), point(111.621094, 40.913513) ) / 0.0111 ) * 1000 ) AS distance FROM locationpoint ORDER BY distance;
查詢結(jié)果
以上就是MySQL怎么計(jì)算兩坐標(biāo)距離并排序的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注億速云其它相關(guān)文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。