回答編集履歴

1

追記修正

2019/05/06 01:27

投稿

YAmaGNZ
YAmaGNZ

スコア10242

test CHANGED
@@ -8,15 +8,15 @@
8
8
 
9
9
  ,tmp.勤務帯
10
10
 
11
- ,max(case DAY(tmp.日付) when 1 then tmp.生産台数 else null end) as [1日]
11
+ ,sum(case DAY(tmp.日付) when 1 then tmp.生産台数 else null end) as [1日]
12
12
 
13
- ,max(case DAY(tmp.日付) when 2 then tmp.生産台数 else null end) as [2日]
13
+ ,sum(case DAY(tmp.日付) when 2 then tmp.生産台数 else null end) as [2日]
14
14
 
15
- ,max(case DAY(tmp.日付) when 3 then tmp.生産台数 else null end) as [3日]
15
+ ,sum(case DAY(tmp.日付) when 3 then tmp.生産台数 else null end) as [3日]
16
16
 
17
- ,max(case DAY(tmp.日付) when 4 then tmp.生産台数 else null end) as [4日]
17
+ ,sum(case DAY(tmp.日付) when 4 then tmp.生産台数 else null end) as [4日]
18
18
 
19
- ,max(case DAY(tmp.日付) when 5 then tmp.生産台数 else null end) as [5日]
19
+ ,sum(case DAY(tmp.日付) when 5 then tmp.生産台数 else null end) as [5日]
20
20
 
21
21
  from
22
22
 
@@ -31,6 +31,28 @@
31
31
  tmp.製品名 , tmp.現場 , tmp.勤務帯
32
32
 
33
33
 
34
+
35
+ ```
36
+
37
+ もしくは
38
+
39
+ ```SQL
40
+
41
+ select 製品名 , 現場 , 勤務帯 ,[1] ,[2] ,[3] ,[4] ,[5]
42
+
43
+ from
44
+
45
+ (select DAY(日付) AS 日 , 製品名 , 現場 , 勤務帯 , 生産台数 from keikaku) tmp
46
+
47
+ PIVOT ( SUM( 生産台数 ) FOR 日 IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10]
48
+
49
+ ,[11],[12],[13],[14],[15],[16],[17],[18],[19],[20]
50
+
51
+ ,[21],[22],[23],[24],[25],[26],[27],[28],[29],[30],[31]
52
+
53
+ )) AS p
54
+
55
+ ORDER BY 製品名 , 現場 , 勤務帯
34
56
 
35
57
  ```
36
58
 
@@ -54,4 +76,20 @@
54
76
 
55
77
  ```
56
78
 
79
+ もしくは
80
+
81
+ ```VB.NET
82
+
83
+ SQL = "select 製品名 , 現場 , 勤務帯"
84
+
85
+ For i = 1 to その月の最終日
86
+
87
+ SQL &= $",[{i}]"
88
+
89
+ Next
90
+
91
+
92
+
93
+ ```
94
+
57
95
  このような感じで