回答編集履歴

3

update

2020/02/27 00:06

投稿

amura
amura

スコア333

test CHANGED
@@ -24,6 +24,8 @@
24
24
 
25
25
  ) tbl1
26
26
 
27
+ join questions using(questionID)
28
+
27
29
  group by questionID order by questionID;
28
30
 
29
31
  ```

2

update

2020/02/27 00:05

投稿

amura
amura

スコア333

test CHANGED
@@ -1,4 +1,4 @@
1
- 2つSQLの結果をUNIONしてみました。
1
+ 2つSQLの結果をUNIONしてみました。questionsも加えました
2
2
 
3
3
  ```sql
4
4
 
@@ -12,15 +12,17 @@
12
12
 
13
13
  from (select questionID ,0 as answerValue, sum(reaction=0) as goodCount,sum(reaction=1) as badCount
14
14
 
15
- from questionReaction group by questionID
15
+ from questionReaction group by questionID
16
16
 
17
17
  union all
18
18
 
19
- select questionID, count(questionID) as answerValue, 0, 0 from answerTable group by questionID
19
+ select questionID, count(questionID) as answerValue, 0 , 0 from answerTable group by questionID
20
20
 
21
- ) tbl1
21
+ union all
22
22
 
23
- join questions using(questionID)
23
+ select questionID, 0, 0, 0 from questions
24
+
25
+ ) tbl1
24
26
 
25
27
  group by questionID order by questionID;
26
28
 

1

update

2020/02/27 00:03

投稿

amura
amura

スコア333

test CHANGED
@@ -10,13 +10,13 @@
10
10
 
11
11
  sum(badCount) badCount
12
12
 
13
- from (select questionID ,null as answerValue, sum(reaction=0) as goodCount,sum(reaction=1) as badCount
13
+ from (select questionID ,0 as answerValue, sum(reaction=0) as goodCount,sum(reaction=1) as badCount
14
14
 
15
15
  from questionReaction group by questionID
16
16
 
17
17
  union all
18
18
 
19
- select questionID, count(questionID) as answerValue, null, null from answerTable group by questionID
19
+ select questionID, count(questionID) as answerValue, 0, 0 from answerTable group by questionID
20
20
 
21
21
  ) tbl1
22
22