teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

補足を追記

2016/09/28 06:17

投稿

KiyoshiMotoki
KiyoshiMotoki

スコア4791

answer CHANGED
@@ -98,4 +98,18 @@
98
98
  | 400 | 400 | 400 | 1200 |
99
99
  +-------+-------+-------+---------+
100
100
  3 rows in set (0.00 sec)
101
- ```
101
+ ```
102
+
103
+ # 追記
104
+
105
+ MySQLでは、`col_1, col_2, col_3`のいずれかが NULL の場合、
106
+ ```
107
+ col_1 + col_2 + col_3 = NULL
108
+ ```
109
+ となります。
110
+ [https://dev.mysql.com/doc/refman/5.6/ja/problems-with-null.html](https://dev.mysql.com/doc/refman/5.6/ja/problems-with-null.html)
111
+ > NULL を含む式は、式に関連する演算子および関数のドキュメントに示されている場合を除き、常に NULL 値を生成します。
112
+
113
+ "合計をだしたカラム"に NULL が格納されるのを避けたい場合、
114
+ yambejp様のコメントにある通り、`col_1, col_2, col_3`に NOT NULL 制約をつけるか、
115
+ NULL を適切な値に変換した上で合計を計算するなどの対処をしてください。