Kylin和Hive 取每组的TOP1 之间的区别

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

采用 row_number() over 函数,但是Hive和kylin之间写法是有区别的

Hive的取数是这样的:

select t.customerid,t.tagid from 
(select *,row_number() over (partition by customerid,tagid order by time desc) num 
from dm.DM_TAG2CUSTOMER) t where t.num=1 and t.insert_or_delete=1

Kylin的取数是这样的:

select t.customerid,t.tagid from 
(select *,row_number() over (partition by customerid,tagid order by createtime desc) num
from dm.DM_TAG2CUSTOMER) t inner join (select 1 a) s
on t.num=s.a where t.insert_or_delete=1

 

转载于:https://my.oschina.net/ilovetao/blog/1574396

你可能感兴趣的:(Kylin和Hive 取每组的TOP1 之间的区别)