hql 实现分组排序功能
hql是hive的查询语言,十分类似mysql的,分组排序也是通过row_number() over(partition by )实现的。
创建如下表
hive> desc ods_pss_product_price_history;
OK
id bigint
create_uid bigint
create_date string
product_id bigint
company_id bigint
datetime string
cost float
write_date string
write_uid bigint
dt string
实现功能如下
首先根据product_id分组,在根据id和create_date倒叙排序
实现方法如下
select create_date, product_id, company_id, cost,
row_number()over(partition by product_id order by id desc, create_date desc) r
from ods_pss_product_price_history a where company_id = 1 and cost>0 limit 100;