回答編集履歴
4
追記
answer
CHANGED
@@ -17,7 +17,8 @@
|
|
17
17
|
```
|
18
18
|
※[NO, 登録日]のインデックスはあった方が良いでしょう。
|
19
19
|
|
20
|
-
質問の内容が、同NOで最新の登録日と一つ前の登録日の比較という事でしたら、
|
20
|
+
質問の内容が、同NOで最新の登録日と一つ前の登録日の比較という事でしたら、以下です。
|
21
|
+
※違う名称のものと比較するという事は考え辛いので、多分こういう事かなと思います。
|
21
22
|
```SQL
|
22
23
|
select A.[NO], A.名称, A.金額, A.登録日, B.金額, B.登録日
|
23
24
|
from (
|
3
追記
answer
CHANGED
@@ -15,4 +15,20 @@
|
|
15
15
|
on A.[NO]-1=B.[NO] and A.前NO登録日=B.登録日
|
16
16
|
WHERE A.金額 > Nz(B.金額)
|
17
17
|
```
|
18
|
-
※[NO, 登録日]のインデックスはあった方が良いでしょう。
|
18
|
+
※[NO, 登録日]のインデックスはあった方が良いでしょう。
|
19
|
+
|
20
|
+
質問の内容が、同NOで最新の登録日と一つ前の登録日の比較という事でしたら、
|
21
|
+
```SQL
|
22
|
+
select A.[NO], A.名称, A.金額, A.登録日, B.金額, B.登録日
|
23
|
+
from (
|
24
|
+
SELECT t1.*
|
25
|
+
, (select max(登録日) from Teble
|
26
|
+
where [NO]=t1.[NO] and 登録日< t1.登録日
|
27
|
+
) as 前登録日
|
28
|
+
FROM Teble t1
|
29
|
+
where 登録日=(select Max(登録日) from Table where [NO]=t1.[NO])
|
30
|
+
) as A
|
31
|
+
left join Teble as B
|
32
|
+
on A.[NO]=B.[NO] and A.前登録日=B.登録日
|
33
|
+
WHERE A.金額 > Nz(B.金額)
|
34
|
+
```
|
2
追記
answer
CHANGED
@@ -14,4 +14,5 @@
|
|
14
14
|
left join Teble as B
|
15
15
|
on A.[NO]-1=B.[NO] and A.前NO登録日=B.登録日
|
16
16
|
WHERE A.金額 > Nz(B.金額)
|
17
|
-
```
|
17
|
+
```
|
18
|
+
※[NO, 登録日]のインデックスはあった方が良いでしょう。
|
1
修正
answer
CHANGED
@@ -8,10 +8,10 @@
|
|
8
8
|
```SQL
|
9
9
|
select A.[NO], A.名称, A.金額, A.登録日, B.金額, B.登録日
|
10
10
|
from (
|
11
|
-
SELECT t1.*, (select max(登録日) from Teble where [NO]
|
11
|
+
SELECT t1.*, (select max(登録日) from Teble where [NO]=t1.[NO]-1) as 前NO登録日
|
12
12
|
FROM Teble t1
|
13
13
|
) as A
|
14
14
|
left join Teble as B
|
15
|
-
on A.[NO]=B.[NO]
|
15
|
+
on A.[NO]-1=B.[NO] and A.前NO登録日=B.登録日
|
16
16
|
WHERE A.金額 > Nz(B.金額)
|
17
17
|
```
|