回答編集履歴

3

修正

2018/04/09 14:25

投稿

sazi
sazi

スコア25173

test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ```
12
12
 
13
- ここから、商品を外し、施設別に一行で表示したいので、
13
+ ここから、商品を外し、施設別に一行で表示したいので、
14
14
 
15
15
  ```SQL
16
16
 

2

修正

2018/04/09 14:25

投稿

sazi
sazi

スコア25173

test CHANGED
@@ -10,31 +10,7 @@
10
10
 
11
11
  ```
12
12
 
13
- ここから、商品を外すと、
14
-
15
- ```SQL
16
-
17
- select 施設cd,
18
-
19
- case when 商品=みかん then 売上日 end as みかん,
20
-
21
- case when 商品=りんご then 売上日 end as りんご,
22
-
23
- case when 商品=いちご then 売上日 end as いちご
24
-
25
- from sale
26
-
27
- group by 施設cd, 売上日
28
-
29
- ```
30
-
31
- さらに、
32
-
33
- > 施設別に一行で表示したい
13
+ ここから、商品を外すし、施設別に一行で表示したいので、
34
-
35
-
36
-
37
- ので、
38
14
 
39
15
  ```SQL
40
16
 

1

追記

2018/04/09 14:22

投稿

sazi
sazi

スコア25173

test CHANGED
@@ -10,20 +10,44 @@
10
10
 
11
11
  ```
12
12
 
13
- ここから、商品を外すので
13
+ ここから、商品を外す
14
14
 
15
15
  ```SQL
16
16
 
17
17
  select 施設cd,
18
18
 
19
- case when 商品=みかん then 売上日 endas みかん,
19
+ case when 商品=みかん then 売上日 end as みかん,
20
20
 
21
- case when 商品=りんご then 売上日 endas りんご,
21
+ case when 商品=りんご then 売上日 end as りんご,
22
22
 
23
- case when 商品=いちご then 売上日 endas いちご
23
+ case when 商品=いちご then 売上日 end as いちご
24
24
 
25
25
  from sale
26
26
 
27
27
  group by 施設cd, 売上日
28
28
 
29
29
  ```
30
+
31
+ さらに、
32
+
33
+ > 施設別に一行で表示したい。
34
+
35
+
36
+
37
+ ので、
38
+
39
+ ```SQL
40
+
41
+ select 施設cd,
42
+
43
+ max(case when 商品=みかん then 売上日 end) as みかん,
44
+
45
+ max(case when 商品=りんご then 売上日 end) as りんご,
46
+
47
+ max(case when 商品=いちご then 売上日 end) as いちご
48
+
49
+ from sale
50
+
51
+ group by 施設cd
52
+
53
+ ```