回答編集履歴
2
推敲
test
CHANGED
@@ -32,9 +32,9 @@
|
|
32
32
|
|
33
33
|
select date, sum(type_total) sub_total
|
34
34
|
|
35
|
-
, array_agg(type order by type) type_
|
35
|
+
, array_agg(type order by type) type_ary
|
36
36
|
|
37
|
-
, array_agg(type_total order by type) type_total_
|
37
|
+
, array_agg(type_total order by type) type_total_ary
|
38
38
|
|
39
39
|
from (
|
40
40
|
|
1
追記
test
CHANGED
@@ -19,3 +19,37 @@
|
|
19
19
|
GROUP BY date
|
20
20
|
|
21
21
|
```
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
追記
|
26
|
+
|
27
|
+
--
|
28
|
+
|
29
|
+
下記で、type_listにtypeが列挙され、それと同じ並びでtype毎の計が列挙されます。
|
30
|
+
|
31
|
+
```SQL
|
32
|
+
|
33
|
+
select date, sum(type_total) sub_total
|
34
|
+
|
35
|
+
, array_agg(type order by type) type_list
|
36
|
+
|
37
|
+
, array_agg(type_total order by type) type_total_list
|
38
|
+
|
39
|
+
from (
|
40
|
+
|
41
|
+
SELECT date, type, SUM(amount) AS type_total
|
42
|
+
|
43
|
+
FROM table t1 left join type_table t2
|
44
|
+
|
45
|
+
on t1.type_id=t2.type_id
|
46
|
+
|
47
|
+
GROUP BY date, type
|
48
|
+
|
49
|
+
) step1
|
50
|
+
|
51
|
+
group by date
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
後は受け取るプログラム側で、typeテーブルで列の数を決めて、該当する箇所に埋め込むようにします。
|