在配置单元的子组中使用秩

xmakbtuz  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(367)

嘿,我正在尝试使用 rank() 但我运气不好,

select t.orig, t.id, count(*) as num_actions, 
rank() over (partition by t.orig order by count(*) desc) as rank
from sample_table t
where rank < 21 
and t.month in (201607,20608,201609,201610,201611,201612) 
and t.orig in (select tw.pageid from tw_sample as tw limit 50) 
group by t.orig, t.id

我一直在想,
失败:semanticexception[错误10004]:行4:6无效的表别名或列引用“rank”
我的目标是为每一位选手争取前20排 t.orig 基于 count(*) 参数。
如果你也能解释一下我哪里出错了,这样我就可以从中吸取教训,那将不胜感激。

py49o6xq

py49o6xq1#

不能在中使用别名 where 条款。使用子查询:

select *
from (select t.orig, t.id, count(*) as num_actions, 
             rank() over (partition by t.orig order by count(*) desc) as rnk
      from sample_table t
      where t.month in (201607, 20608, 201609, 201610, 201611, 201612)  and
            t.orig in (select tw.pageid from tw_sample tw limit 50) 
      group by t.orig, t.id
     ) t
where rank < 21

相关问题