Hive经典面试SQL题

Hive经典面试SQL题_第1张图片

select id,
	mid_date,
	price 
from (	
		select 
			tmp.*, 
			t.*, 
			date_add(day, pos) as mid_date 
		from (	
				select id,
						day,
						if(day2 is not null,day2,day) day2,
						price 
				from (
						select id,
								day,
								lead(date_sub(day,1)) over(partition by id order by day asc) day2,
								price 
						from table1
				)tmp1
		)tmp lateral view posexplode( split( space( datediff( day2, day ) ), '' ) ) t as pos, val
)tmp2;

你可能感兴趣的:(hive企业级调优)