提交 4a0722eb authored 作者: Thomas Mueller's avatar Thomas Mueller

SUM on a boolean expression will now count the number of 'true' rows.

上级 89e4ea89
......@@ -395,10 +395,14 @@ public class Aggregate extends Expression {
precision = displaySize = Integer.MAX_VALUE;
break;
case SUM:
if (!DataType.supportsAdd(dataType)) {
if (dataType == Value.BOOLEAN) {
// example: sum(id > 3) (count the rows)
dataType = Value.LONG;
} else if (!DataType.supportsAdd(dataType)) {
throw DbException.get(ErrorCode.SUM_OR_AVG_ON_WRONG_DATATYPE_1, getSQL());
} else {
dataType = DataType.getAddProofType(dataType);
}
dataType = DataType.getAddProofType(dataType);
break;
case AVG:
if (!DataType.supportsAdd(dataType)) {
......
select sum(mod(x, 2) = 1) from system_range(1, 10);
> 5;
create table a(x int);
create table b(x int);
select count(*) from (select b.x from a left join b);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论