mysql> select sum(distinct id), sum(distinct int_col) from alltypesagg;
+--------------------+-------------------------+
| sum(DISTINCT id
) | sum(DISTINCT int_col
) |
+--------------------+-------------------------+
| 0 | 0 |
+--------------------+-------------------------+
1 row in set (0.01 sec)
mysql> select sum(distinct id) from alltypesagg;
+--------------------+
| sum(DISTINCT id
) |
+--------------------+
| NULL |
+--------------------+
1 row in set (0.01 sec)
当表中没有数据时,sum distinct应该返回NULL, 而不是0,因为0对sum聚合函数来说是有意义的数。单个sum distinct计算结果没有问题,但是多个sum distinct的计算结果有问题。
暂无答案!
目前还没有任何答案,快来回答吧!