table
id score
1 23
2 33table2
id score
4 22
6 45
SELECT A.id,B.id,SUM(A.score+B.score) FROM table A LEFT JOIN table B ON A.id=B.id我们知道,此left join并未查到东西。但是
id SUM()
NULL NULL
我的意思是不想显示null.应该是空值才是我要的。
如何办啊?试了以下方法,未成功。
where id>0
where id is not null
sum(COALESCE(A.score,0)+COALESCE(B.score,0))怎么才能实现,空集?
id score
1 23
2 33table2
id score
4 22
6 45
SELECT A.id,B.id,SUM(A.score+B.score) FROM table A LEFT JOIN table B ON A.id=B.id我们知道,此left join并未查到东西。但是
id SUM()
NULL NULL
我的意思是不想显示null.应该是空值才是我要的。
如何办啊?试了以下方法,未成功。
where id>0
where id is not null
sum(COALESCE(A.score,0)+COALESCE(B.score,0))怎么才能实现,空集?
+------+-------+-----------+
| id | t2_id | score_sum |
+------+-------+-----------+
| 1 | | |
| 2 | | |
+------+-------+-----------+
2 rows in set (0.00 sec)
SUM函数经常用于多行累加的.
LEFT JOIN table B
ON A.id=B.id;
LEFT JOIN table B
ON A.id=B.id;