回答編集履歴
1
更新
test
CHANGED
@@ -25,3 +25,43 @@
|
|
25
25
|
) and 日付<'2999/12/31'
|
26
26
|
|
27
27
|
```
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
# 修正
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```SQL
|
36
|
+
|
37
|
+
create table tbl(伝票番号 varchar(10),明細 varchar(10),日付 date,金額 int);
|
38
|
+
|
39
|
+
insert into tbl values
|
40
|
+
|
41
|
+
('0001','001','2011/11/01','1900'),
|
42
|
+
|
43
|
+
('0001','002','2011/11/02','2900'),
|
44
|
+
|
45
|
+
('0001','003','2011/11/03','5000'),
|
46
|
+
|
47
|
+
('0001','004','2011/11/04','4900'),
|
48
|
+
|
49
|
+
('0001','005','2999/12/31','5900'),
|
50
|
+
|
51
|
+
('0002','001','2011/11/05','5000');
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
2999/12/31を除く最大値の日付を持つ金額
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
```SQL
|
60
|
+
|
61
|
+
select 伝票番号,金額 from tbl as t1 where not exists(
|
62
|
+
|
63
|
+
select 1 from tbl where 日付<'2999/12/31' and t1.日付<日付 and t1.伝票番号=伝票番号
|
64
|
+
|
65
|
+
) and 日付<'2999/12/31' and 伝票番号='0001'
|
66
|
+
|
67
|
+
```
|