玉祥平台客服-15087858732

标题: oracle中按一字段分组后再选出另一字段出现频率最高的 [打印本页]

作者: 张兴康    时间: 2020-7-14 18:13
标题: oracle中按一字段分组后再选出另一字段出现频率最高的
有一个logs表,如下图所示

现在要按照MODULE字段分组再选出DEPT字段中出现频率最高的数据;即:
aaa  002  
bb  001
cc  004

实现方法如下:

具体代码:
  1. with x as
  2. (select module, dept, COUNT(*) c from logs group by module, dept),
  3. xx as
  4. (select x.*, RANK() over(partition by module order by x.c desc) rn from x)
  5. select module,dept from xx  where rn = 1;
复制代码







欢迎光临 玉祥平台客服-15087858732 (http://plat.delit.cn/) Powered by Discuz! X3.2