回答編集履歴
8
修正
test
CHANGED
@@ -44,9 +44,11 @@
|
|
44
44
|
|
45
45
|
select *
|
46
46
|
|
47
|
-
|
47
|
+
from (
|
48
48
|
|
49
|
+
select *,[基準からの距離] as distance from item
|
50
|
+
|
49
|
-
|
51
|
+
) t1
|
50
52
|
|
51
53
|
where state=1
|
52
54
|
|
7
修正
test
CHANGED
@@ -50,7 +50,7 @@
|
|
50
50
|
|
51
51
|
where state=1
|
52
52
|
|
53
|
-
and (
|
53
|
+
and (distance<=25 or add_city = '千代田区')
|
54
54
|
|
55
55
|
ORDER BY distance
|
56
56
|
|
6
order by 追記
test
CHANGED
@@ -34,6 +34,8 @@
|
|
34
34
|
|
35
35
|
)
|
36
36
|
|
37
|
+
ORDER BY distance
|
38
|
+
|
37
39
|
```
|
38
40
|
|
39
41
|
※別にunionじゃなくてorでよかった。
|
@@ -50,4 +52,6 @@
|
|
50
52
|
|
51
53
|
and ([基準からの距離]<=25 or add_city = '千代田区')
|
52
54
|
|
55
|
+
ORDER BY distance
|
56
|
+
|
53
57
|
```
|
5
推敲
test
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
|
37
37
|
```
|
38
38
|
|
39
|
-
※別にunionじゃなくてorで
|
39
|
+
※別にunionじゃなくてorでよかった。
|
40
40
|
|
41
41
|
```SQL
|
42
42
|
|
4
推敲
test
CHANGED
@@ -48,6 +48,6 @@
|
|
48
48
|
|
49
49
|
where state=1
|
50
50
|
|
51
|
-
and ([基準からの距離]<=25 or
|
51
|
+
and ([基準からの距離]<=25 or add_city = '千代田区')
|
52
52
|
|
53
53
|
```
|
3
補足と推敲
test
CHANGED
@@ -14,7 +14,9 @@
|
|
14
14
|
|
15
15
|
```SQL
|
16
16
|
|
17
|
-
select *
|
17
|
+
select *
|
18
|
+
|
19
|
+
,[基準からの距離] as distance
|
18
20
|
|
19
21
|
where id in (
|
20
22
|
|
@@ -22,7 +24,7 @@
|
|
22
24
|
|
23
25
|
where state=1
|
24
26
|
|
25
|
-
and
|
27
|
+
and [基準からの距離]<=25
|
26
28
|
|
27
29
|
union all
|
28
30
|
|
@@ -33,3 +35,19 @@
|
|
33
35
|
)
|
34
36
|
|
35
37
|
```
|
38
|
+
|
39
|
+
※別にunionじゃなくてorで良い気がしますが。
|
40
|
+
|
41
|
+
```SQL
|
42
|
+
|
43
|
+
select *
|
44
|
+
|
45
|
+
,[基準からの距離] as distance
|
46
|
+
|
47
|
+
from item
|
48
|
+
|
49
|
+
where state=1
|
50
|
+
|
51
|
+
and ([基準からの距離]<=25 or or add_city = '千代田区')
|
52
|
+
|
53
|
+
```
|
2
推敲
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
--
|
10
10
|
|
11
|
-
補足をみるとAまたはBの集合ってこと
|
11
|
+
補足をみるとAまたはBの集合ってことの様ですね。
|
12
12
|
|
13
13
|
でしたら、
|
14
14
|
|
1
補足に対する追記
test
CHANGED
@@ -1,3 +1,35 @@
|
|
1
1
|
条件としては、「千代田区で緯度35.694003、経度139.753595から半径25km内の距離にあるもの」ではないですか?
|
2
2
|
|
3
3
|
だとしたら、最初のSQLのwhere条件に「AND add_city = '千代田区'」を加えるだけだと思いますけど。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
追記
|
8
|
+
|
9
|
+
--
|
10
|
+
|
11
|
+
補足をみるとAまたはBの集合ってことようですね。
|
12
|
+
|
13
|
+
でしたら、
|
14
|
+
|
15
|
+
```SQL
|
16
|
+
|
17
|
+
select * from item
|
18
|
+
|
19
|
+
where id in (
|
20
|
+
|
21
|
+
select id from item
|
22
|
+
|
23
|
+
where state=1
|
24
|
+
|
25
|
+
and (6371 * ACOS(COS(RADIANS(35.694003)) * COS(RADIANS(add_lat))*COS(RADIANS(add_long) - RADIANS(139.753595)) + SIN(RADIANS(35.694003)) * SIN(RADIANS(add_lat)))) <= 25
|
26
|
+
|
27
|
+
union all
|
28
|
+
|
29
|
+
select id from item
|
30
|
+
|
31
|
+
where state=1 AND add_city = '千代田区'
|
32
|
+
|
33
|
+
)
|
34
|
+
|
35
|
+
```
|