回答編集履歴
4
追記
test
CHANGED
@@ -19,3 +19,27 @@
|
|
19
19
|
and end_date is not null
|
20
20
|
|
21
21
|
```
|
22
|
+
|
23
|
+
どっちが低コストか分かりませんが、別パターン
|
24
|
+
|
25
|
+
```SQL
|
26
|
+
|
27
|
+
SELECT m.id, m.name, mi.start_date, mi.end_date
|
28
|
+
|
29
|
+
from member_item mi inner join member m
|
30
|
+
|
31
|
+
om mi.menber_id = m.id
|
32
|
+
|
33
|
+
where (mi.menber_id, mi.start_date) in (
|
34
|
+
|
35
|
+
select menber_id, max(start_Date)
|
36
|
+
|
37
|
+
from member_item
|
38
|
+
|
39
|
+
group by menber_id
|
40
|
+
|
41
|
+
)
|
42
|
+
|
43
|
+
and end_date is not null
|
44
|
+
|
45
|
+
```
|
3
推敲
test
CHANGED
@@ -10,7 +10,9 @@
|
|
10
10
|
|
11
11
|
where not exists(
|
12
12
|
|
13
|
+
select 1 from member_item
|
14
|
+
|
13
|
-
|
15
|
+
where menber_id=mi.menber_id and start_date > mi.start_date
|
14
16
|
|
15
17
|
)
|
16
18
|
|
2
推敲
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
```SQL
|
4
4
|
|
5
|
-
se
|
5
|
+
SELECT m.id, m.name, mi.start_date, mi.end_date
|
6
6
|
|
7
7
|
from member_item mi inner join member m
|
8
8
|
|
1
追記
test
CHANGED
@@ -4,7 +4,9 @@
|
|
4
4
|
|
5
5
|
select *
|
6
6
|
|
7
|
+
from member_item mi inner join member m
|
8
|
+
|
7
|
-
|
9
|
+
om mi.menber_id = m.id
|
8
10
|
|
9
11
|
where not exists(
|
10
12
|
|