如何分组统计唯一值的数量

文档说 distinct 暂不支持和 group by 连用,如果我需要书写 select count(distinct xx) from t group by yy 这种语句,有没有什么简单的方法?

目前我的解决方案如下,感觉代码有点复杂:

select
BuyOrderNum: count BidOrder
from
(select distinct BidOrder,date,WindCode from transTemp) group by date,WindCode
请先 登录 后评论

1 个回答

veryOrdinary

可以用 nunique 替换 count(distinct), nuique 可以搭配 group by 使用,上述脚本可以改写为:

select BuyOrderNum: nunique BidOrder from transTemp group by date,WindCode
请先 登录 后评论