有这样一张表
score1, scroe2, score3
---------------------
NULL NULL 9select score1+scroe2+score3 结果是NULL
要怎么才能让结果为9呢
score1, scroe2, score3
---------------------
NULL NULL 9select score1+scroe2+score3 结果是NULL
要怎么才能让结果为9呢
看我的测试select * from test;
select score1+ifnull(score2,0)+ifnull(score3,0) as total from test;
select score1+(case when score2 is null then 0 else score2 end)+(case when score3 is null then 0 else score3 end) as total from test;
结果:query result(7 records)
id score1 score2 score3
1 45 (NULL) (NULL)
2 345 (NULL) 4
3 454 (NULL) 5
4 4545 (NULL) 3
5 2 45 (NULL)
6 23 6 (NULL)
7 43 (NULL) 6
query result(7 records)
total
45
349
459
4548
47
29
49 query result(7 records)
total
45
349
459
4548
47
29
49