回答編集履歴
4
追記
test
CHANGED
@@ -36,7 +36,9 @@
|
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
-
質問の内容が、同NOで最新の登録日と一つ前の登録日の比較という事でしたら、
|
39
|
+
質問の内容が、同NOで最新の登録日と一つ前の登録日の比較という事でしたら、以下です。
|
40
|
+
|
41
|
+
※違う名称のものと比較するという事は考え辛いので、多分こういう事かなと思います。
|
40
42
|
|
41
43
|
```SQL
|
42
44
|
|
3
追記
test
CHANGED
@@ -33,3 +33,35 @@
|
|
33
33
|
```
|
34
34
|
|
35
35
|
※[NO, 登録日]のインデックスはあった方が良いでしょう。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
質問の内容が、同NOで最新の登録日と一つ前の登録日の比較という事でしたら、
|
40
|
+
|
41
|
+
```SQL
|
42
|
+
|
43
|
+
select A.[NO], A.名称, A.金額, A.登録日, B.金額, B.登録日
|
44
|
+
|
45
|
+
from (
|
46
|
+
|
47
|
+
SELECT t1.*
|
48
|
+
|
49
|
+
, (select max(登録日) from Teble
|
50
|
+
|
51
|
+
where [NO]=t1.[NO] and 登録日< t1.登録日
|
52
|
+
|
53
|
+
) as 前登録日
|
54
|
+
|
55
|
+
FROM Teble t1
|
56
|
+
|
57
|
+
where 登録日=(select Max(登録日) from Table where [NO]=t1.[NO])
|
58
|
+
|
59
|
+
) as A
|
60
|
+
|
61
|
+
left join Teble as B
|
62
|
+
|
63
|
+
on A.[NO]=B.[NO] and A.前登録日=B.登録日
|
64
|
+
|
65
|
+
WHERE A.金額 > Nz(B.金額)
|
66
|
+
|
67
|
+
```
|
2
追記
test
CHANGED
@@ -31,3 +31,5 @@
|
|
31
31
|
WHERE A.金額 > Nz(B.金額)
|
32
32
|
|
33
33
|
```
|
34
|
+
|
35
|
+
※[NO, 登録日]のインデックスはあった方が良いでしょう。
|
1
修正
test
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
from (
|
20
20
|
|
21
|
-
SELECT t1.*, (select max(登録日) from Teble where [NO]
|
21
|
+
SELECT t1.*, (select max(登録日) from Teble where [NO]=t1.[NO]-1) as 前NO登録日
|
22
22
|
|
23
23
|
FROM Teble t1
|
24
24
|
|
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
left join Teble as B
|
28
28
|
|
29
|
-
on A.[NO]=B.[NO]
|
29
|
+
on A.[NO]-1=B.[NO] and A.前NO登録日=B.登録日
|
30
30
|
|
31
31
|
WHERE A.金額 > Nz(B.金額)
|
32
32
|
|