SQL查询,分组取top n
一、关系型数据库 mysql:
1、自身join,having count(1) > n
2、嵌套查询,where n < (select count(1) from table where xx=xx)
二、分布式并行计算 hive sql:
使用开窗函数 row_number() over (partition by xx order by xxx)
select *
from
(
select *, row_number() over (partition by 分组字段 order by 排序字段 desc) as od
from
(
数据表
) a
) t
where od<= n

6027

被折叠的 条评论
为什么被折叠?



