質問編集履歴

2

aql変更

2020/09/08 02:44

投稿

ms5025
ms5025

スコア292

test CHANGED
File without changes
test CHANGED
@@ -6,17 +6,21 @@
6
6
 
7
7
  select
8
8
 
9
- case hoge when 1 then aaa
9
+ SUM(CASE WHEN hoge = 1 THEN fuga ELSE 0 END) AS aaaa,
10
10
 
11
- case hoge when 2 then bbb
11
+ SUM(CASE WHEN hoge = 2 THEN fuga ELSE 0 END) AS bbbb,
12
12
 
13
- case hoge when 3 then ccc
13
+ SUM(CASE WHEN hoge = 3 THEN fuga ELSE 0 END) AS cccc,
14
14
 
15
- case hoge when 4 then ddd
15
+ SUM(CASE WHEN hoge = 4 THEN fuga ELSE 0 END) AS dddd,
16
16
 
17
17
  from
18
18
 
19
19
  tab_hoge
20
+
21
+ この辺なんかgroupby
22
+
23
+ よくあるやつ
20
24
 
21
25
 
22
26
 

1

sql文変更

2020/09/08 02:44

投稿

ms5025
ms5025

スコア292

test CHANGED
File without changes
test CHANGED
@@ -2,51 +2,23 @@
2
2
 
3
3
  ```
4
4
 
5
- select
6
5
 
7
- sub.*
8
-
9
- from
10
-
11
- (
12
6
 
13
7
  select
14
8
 
15
- q.employee_id
9
+ case hoge when 1 then aaa
16
10
 
17
- ,case p.seq
11
+ case hoge when 2 then bbb
18
12
 
19
- when 1 then q.qualification_id_1
13
+ case hoge when 3 then ccc
20
14
 
21
- when 2 then q.qualification_id_2
22
-
23
- when 3 then q.qualification_id_3
24
-
25
- when 4 then q.qualification_id_4
26
-
27
- end as qualification_id
15
+ case hoge when 4 then ddd
28
16
 
29
17
  from
30
18
 
31
- qualifications_horizontal as q
19
+ tab_hoge
32
20
 
33
- cross join
34
21
 
35
- pivot as p
36
-
37
- ) sub
38
-
39
- where
40
-
41
- sub.qualification_id is not null
42
-
43
- order by
44
-
45
- sub.employee_id
46
-
47
- ,sub.qualification_id
48
-
49
- ;
50
22
 
51
23
  ```
52
24