我导入了一个由POINT数据组成的shapefile。
以下是查询:
SELECT a.name,
ST_Distance(ST_GeographyFromText(ST_AsText(a.geom)),
ST_GeographyFromText(ST_AsText(b.geom)))/1000 AS distance
FROM places a, places b
WHERE b.name='Mumbai';
此查询显示“孟买”的地点距离(以KM为单位)。
给出输出:
name | distance
--------------------------------------------------+------------------
Mumbai | 0
New Delhi | 1159.26223973831
Pune | 117.86639722221
Vittalpuram | 1058.49956760668
Kadapakkam | 1064.4166204267
Chellampatty | 1136.24329302432
Srirampur | 205.27117214342
Bhorvadi | 213.69790081481
Vaduj | 227.66082105079
Pushkar | 853.0369297591
Orcha | 927.67801469371
Phillaur | 1369.21450470719
Goraya | 1381.0316667358
Phagwara | 1390.76210842565
Ludhiana | 1358.93226658828
Mohali | 1361.88704243237
Morinda | 1362.40782426879
Kurali | 1368.92321753998
Rupnagar | 1382.46666378301
Moga | 1335.85239784081
Pahalgām | 1689.72733587196
Ambala | 1327.24107571448
Doraha | 1351.41408180716
Entrance of Ranjeet Avenue | 1351.43744476875
Shaheed Jasdev Singh Nagar | 1353.19967929777
Jagbir House | 1357.58692404013
Rania | 1350.48320804851
Pawa | 1354.30374843403
Sreenh | 1347.01369530847
Kaind | 1345.76155280418
Dharour | 1352.71636605571
TIBBA | 1350.96268614694
NAAT | 1351.965780883
Harnampura | 1350.90891035291
Nandpur | 1354.12810806732
Umadpur | 1350.92919575633
Dugri | 1350.23846455405
Dehlon intersection | 1341.15103218979
Alwarpet | 1029.21518660807
Teynampet | 1028.07582220005
Gopalapuram | 1028.37800837912
Nandanam | 1028.41251498301
Raja Annamalai Puram | 1029.83876612634
Abhiramapuram | 1029.72834342923
CIT Colony | 1029.16938386861
Sriperumbudur | 1009.05941189302
Poonamallee | 1015.86523604896
现在我打算过滤掉结果,以便查看距离<= 500的地方。我怎样才能实现这个目标?
答案 0 :(得分:0)
将您的查询用作子选择:
SELECT *
FROM (SELECT a.name ...) dummy
WHERE distance < 500.0;