回答編集履歴
2
追記
test
CHANGED
@@ -35,3 +35,75 @@
|
|
35
35
|
articles=(flag, id)
|
36
36
|
|
37
37
|
※項目の並びは、カーディナリティに合わせて適宜変更が必要です。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
追記
|
42
|
+
|
43
|
+
--
|
44
|
+
|
45
|
+
※SQLが変更されたので、内容に合わせて追記
|
46
|
+
|
47
|
+
素直に記述。
|
48
|
+
|
49
|
+
```SQL
|
50
|
+
|
51
|
+
SELECT * FROM facilities_trait
|
52
|
+
|
53
|
+
WHERE flag = 2 AND type in (1, 3)
|
54
|
+
|
55
|
+
AND trait_id in (
|
56
|
+
|
57
|
+
SELECT id FROM articles
|
58
|
+
|
59
|
+
WHERE flag = 2
|
60
|
+
|
61
|
+
AND id in (
|
62
|
+
|
63
|
+
SELECT articles_id FROM rooms
|
64
|
+
|
65
|
+
WHERE flag = 2 AND status = 2
|
66
|
+
|
67
|
+
AND id in (
|
68
|
+
|
69
|
+
SELECT trait_id FROM facilities_trait
|
70
|
+
|
71
|
+
WHERE facilities_id = 31
|
72
|
+
|
73
|
+
)
|
74
|
+
|
75
|
+
)
|
76
|
+
|
77
|
+
)
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
条件内をJoinで。
|
82
|
+
|
83
|
+
```SQL
|
84
|
+
|
85
|
+
SELECT * FROM facilities_trait
|
86
|
+
|
87
|
+
WHERE flag = 2 AND type in (1, 3)
|
88
|
+
|
89
|
+
AND trait_id in (
|
90
|
+
|
91
|
+
select articles.id
|
92
|
+
|
93
|
+
FROM articles
|
94
|
+
|
95
|
+
inner join rooms
|
96
|
+
|
97
|
+
on articles.id = rooms.articles_id
|
98
|
+
|
99
|
+
and articles.flag = 2 and room.flag = 2 AND room.status = 2
|
100
|
+
|
101
|
+
inner join facilities_trait
|
102
|
+
|
103
|
+
on rooms.id=facilities_trait.trait_id
|
104
|
+
|
105
|
+
and facilities_trait.facilities_id = 31
|
106
|
+
|
107
|
+
)
|
108
|
+
|
109
|
+
```
|
1
推敲
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
facilities_trait=(flag, type, facilities_id, rooms_id)
|
32
32
|
|
33
|
-
rooms=(flag, status, id)
|
33
|
+
rooms=(flag, status, articles_id, id)
|
34
34
|
|
35
35
|
articles=(flag, id)
|
36
36
|
|