在group by时怎么去重统计

请问,count(distinct x)写法在group by语句下无法执行,请问还有别的方法可以做到去重统计吗?

比如,在DolphinDB database的GUI中执行下列语句:

t=table(3 2 2 3 3 4 as x,1 1 1 2 2 2 as code);
select count(distinct x ) from t group by code;

报错:
Can't call an aggregated function in the argument of another aggregated function call.但去掉其中的group by是可以的。

请先 登录 后评论

1 个回答

Jason Tang - 时序数据库技术支持

可用DolphinD中的nunique函数实现,此函数可计算向量中非重复值的个数。

select nunique( x from t group by code;
请先 登录 后评论