分组取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;