hive获取历史静默商户余额,半笛卡尔积

hive获取历史静默商户余额,半笛卡尔积

实现:

select
n.date,n.id,n.money
from
(
 select
 ROW_NUMBER() OVER(PARTITION BY m.date,m.id ORDER BY m.date1 desc) AS rn 
 m.date,m.id,m.money
 from (
 select 
 dim.date,table.date as date1,dim.id,table.money
 from dim,table
 where dim.date>=table.date and dim.id=table.id
 ) m 
) n
where n.rn=1 and m.money>0

题解:


20200801 20200801 1  1000
20200802 20200801 1  1000
20200802 20200802 1  2000
20200803 20200801 1  1000
20200803 20200802 1  2000
20200804 20200801 1  1000
20200804 20200802 1  2000
20200805 20200801 1  1000
20200805 20200802 1  2000
20200805 20200805 1  5000