回答編集履歴
1
sample
test
CHANGED
@@ -9,3 +9,51 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
のいずれかが妥当です
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
# sample
|
16
|
+
|
17
|
+
もし日付を先に抜き出して集計表を作る場合は以下のようになります
|
18
|
+
|
19
|
+
- 元データ
|
20
|
+
|
21
|
+
```SQL
|
22
|
+
|
23
|
+
create table person(no int,d date,weight double);
|
24
|
+
|
25
|
+
insert into person values(1,'2015-04-01',60),(1,'2016-04-01',62),(2,'2014-04-01',61),(2,'2015-04-01',66),(2,'2016-04-01',64);
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
- 日付抜き出し
|
32
|
+
|
33
|
+
```SQL
|
34
|
+
|
35
|
+
select distinct d from person order by d asc;
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
- 集計表
|
42
|
+
|
43
|
+
```SQL
|
44
|
+
|
45
|
+
select no
|
46
|
+
|
47
|
+
,sum(weight*(d='2014-04-01')) as `2014-04-01`
|
48
|
+
|
49
|
+
,sum(weight*(d='2015-04-01')) as `2015-04-01`
|
50
|
+
|
51
|
+
,sum(weight*(d='2016-04-01')) as `2016-04-01`
|
52
|
+
|
53
|
+
from person
|
54
|
+
|
55
|
+
group by no
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
※sum・・・の箇所をプログラム吐き出します
|