回答編集履歴

1

更新

2018/11/21 05:15

投稿

yambejp
yambejp

スコア117944

answer CHANGED
@@ -11,4 +11,24 @@
11
11
  select * from tbl as t1 where not exists(
12
12
  select 1 from tbl where and 日付<'2999/12/31' and t1.金額<金額
13
13
  ) and 日付<'2999/12/31'
14
+ ```
15
+
16
+ # 修正
17
+
18
+ ```SQL
19
+ create table tbl(伝票番号 varchar(10),明細 varchar(10),日付 date,金額 int);
20
+ insert into tbl values
21
+ ('0001','001','2011/11/01','1900'),
22
+ ('0001','002','2011/11/02','2900'),
23
+ ('0001','003','2011/11/03','5000'),
24
+ ('0001','004','2011/11/04','4900'),
25
+ ('0001','005','2999/12/31','5900'),
26
+ ('0002','001','2011/11/05','5000');
27
+ ```
28
+ 2999/12/31を除く最大値の日付を持つ金額
29
+
30
+ ```SQL
31
+ select 伝票番号,金額 from tbl as t1 where not exists(
32
+ select 1 from tbl where 日付<'2999/12/31' and t1.日付<日付 and t1.伝票番号=伝票番号
33
+ ) and 日付<'2999/12/31' and 伝票番号='0001'
14
34
  ```