|
有一个logs表,如下图所示
现在要按照MODULE字段分组再选出DEPT字段中出现频率最高的数据;即:
aaa 002
bb 001
cc 004
实现方法如下:
具体代码:
- with x as
- (select module, dept, COUNT(*) c from logs group by module, dept),
- xx as
- (select x.*, RANK() over(partition by module order by x.c desc) rn from x)
- select module,dept from xx where rn = 1;
复制代码
|
|