分组取topN

# 分组取topn

create table t_0428(id UInt32,nm String,cnt UInt32) ENGINE=MergeTree() order by id;

insert into t_0428 values(1,'a',100),(1,'b',101),(1,'c',99),(2,'a',32),(2,'b',55);

select id, arrayElement(groupArray(1)(cnt),1) from (select id,cnt from t_0428 order by id, cnt desc) group by id;

  

posted @ 2021-04-28 14:46  muyue123  阅读(239)  评论(0编辑  收藏  举报