提交 d3fd2d02 编写于 作者: M Mars Liu

makeup exercises

上级 8421dbfa
......@@ -4,6 +4,6 @@
"children": [],
"export": [
"create_table.json",
"anylze.json"
"analyze.json"
]
}
\ No newline at end of file
{
"node_id": "pg-3bbe12c0a19d4cb7a61dc0a20624ed89",
"keywords": [],
"keywords": ["gis", "地理信息"],
"children": [],
"export": []
"export": ["gis.json"]
}
\ No newline at end of file
{
"type": "code_options",
"author": "刘鑫",
"source": "gis.md",
"notebook_enable": false,
"exercise_id": "88b033cd97c642ef9900e5e091e335ff"
}
\ No newline at end of file
# 邻近查找
我们有一个简化的表结构如下:
```postgresql
create table city
(
id serial8,
city text,
poi point
);
create index idx_tbl_point on city using gist (poi) with (buffering = on);
```
要查找给定的点位于哪个城市,或者离哪个城市最近,应该是下列哪一项?
## 答案
```postgresql
select city, poi <-> point($1, $2) dist
from city
where poi <-> point($1, $2) < 100
order by poi <-> point($1, $2)
limit 1;
```
## 选项
### A
```postgresql
select city, poi <-> point($1, $2) dist
from city
where poi <-> point($1, $2) < 100
order by poi <-> point($1, $2) desc
limit 1;
```
### B
```postgresql
select *, poi <-> point($1, $2) dist
from city
where poi <-> point($1, $2) < 100
limit 1;
```
### C
```postgresql
select *, poi - point($1, $2) dist
from city
where poi - point($1, $2) < 100
order by poi - point($1, $2)
limit 1;
```
### D
```postgresql
select *, abs(poi - point($1, $2)) dist
from city
where abs(poi - point($1, $2)) < 100
order by abs(poi - point($1, $2))
limit 1;
```
\ No newline at end of file
......@@ -211,7 +211,11 @@
{
"DDL": {
"node_id": "pg-0378bcd60ccd4dfebcfead92abbdd673",
"keywords": [],
"keywords": [
"创建表",
"授权",
"ddl"
],
"children": []
}
}
......@@ -263,7 +267,10 @@
{
"几何类型和GIS": {
"node_id": "pg-3bbe12c0a19d4cb7a61dc0a20624ed89",
"keywords": [],
"keywords": [
"gis",
"地理信息"
],
"children": []
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册