我有一个表table1 从那我需要显示基于最高计数的前5个操作系统 我需要将它们分组在三个操作系统os,device,model
上当我在查询下执行时,我没有得到任何结果。 在下面的查询中有什么问题?
SELECT * FROM
(SELECT distinct os, count,
DENSE_RANK () OVER (PARTITION BY os ORDER BY count DESC)rn
FROM (Select os ,device,model,SUM(cal_count) as count
from table1
group by os,device,model)b ) a
WHERE a.rn = 5
;
答案 0 :(得分:0)
我会写这样的查询:
select t.*
from (select os, device, model, SUM(cal_count) as cnt,
dense_rank() over (partition by os order by sum(cal_count) desc) as seqnum
from table1
group by os, device, model
) t
where seqnum <= 5;
据我了解你的查询,它只返回每组的第5行。也许存在某种错误。