回答編集履歴
3
訂正
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
and 親部品=s.親部品
|
22
22
|
|
23
|
-
and 変更年月<= to_char(
|
23
|
+
and 変更年月<= to_char(sysdate,'YYYYMM')
|
24
24
|
|
25
25
|
)
|
26
26
|
|
2
修正
test
CHANGED
@@ -1 +1,29 @@
|
|
1
|
-
|
1
|
+
単なる条件では抽出できません。
|
2
|
+
|
3
|
+
同じ親部品内で、現在日以前での過去直近のENDかSTARTのデータをピックアップする必要がありますので、副問合せが必要です。
|
4
|
+
|
5
|
+
```
|
6
|
+
|
7
|
+
select * from sample s
|
8
|
+
|
9
|
+
where 変更キー is null
|
10
|
+
|
11
|
+
or (
|
12
|
+
|
13
|
+
変更キー in ('START', 'END')
|
14
|
+
|
15
|
+
and 変更年月 = (
|
16
|
+
|
17
|
+
select max(変更年月) from sample
|
18
|
+
|
19
|
+
where 変更キー in ('START', 'END')
|
20
|
+
|
21
|
+
and 親部品=s.親部品
|
22
|
+
|
23
|
+
and 変更年月<= to_char(current_date,'YYYYMM')
|
24
|
+
|
25
|
+
)
|
26
|
+
|
27
|
+
)
|
28
|
+
|
29
|
+
```
|
1
訂正
test
CHANGED
@@ -1,21 +1 @@
|
|
1
|
-
|
1
|
+
質問内容の取り違えの為<編集中>
|
2
|
-
|
3
|
-
```SQL
|
4
|
-
|
5
|
-
変更キー not in ('START', 'END')
|
6
|
-
|
7
|
-
or (変更キー = 'START' and 変更年月 <= to_char(sysdate,'YYYYMM'))
|
8
|
-
|
9
|
-
or (変更キー = 'END' and 変更年月 = to_char(sysdate,'YYYYMM'))
|
10
|
-
|
11
|
-
```
|
12
|
-
|
13
|
-
若しくは
|
14
|
-
|
15
|
-
```
|
16
|
-
|
17
|
-
(変更キー != 'END' and 変更年月 <= to_char(sysdate,'YYYYMM'))
|
18
|
-
|
19
|
-
or (変更キー = 'END' and 変更年月 = to_char(sysdate,'YYYYMM'))
|
20
|
-
|
21
|
-
```
|