合并两个表并搜索float + -10

时间:2019-02-14 15:19:28

标签: sql sqlite

我在SQLite数据库中有两个表-学校和人。

Table: schools
+----------+-----+-----+
|   name   |  X  |  Y  |
+----------+-----+-----+
| School 1 | 100 |  40 |
| School 2 |  23 |   2 |
| School 3 |  98 | -50 |
+----------+-----+-----+

...和...

Table: persons
+----------+----------+----------+
|  person  | person_X | person_Y |
+----------+----------+----------+
| Person 1 |       95 |       42 |
| Person 2 |       24 |        4 |
| Person 3 |       98 |      -10 |
| Person 4 |      160 |      111 |
+----------+----------+----------+

我想列出所有在person表中的person_X和person_Y与X和Y匹配的人+ -10。因此,在这种情况下,我希望结果为:Person 1和Person 2(因为它们靠近School 1和School 2)。

我尝试了很多方法,但只能使它起作用。有人可以帮我吗?

1 个答案:

答案 0 :(得分:1)

这仅需要具有检查范围重叠的条件的联接:

gzip

enter image description here

Demo