本文主要是介绍mysql/hive实现lead()不同偏移量数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
由于MySQL中不带有LEAD()函数功能,因此,参考着一篇已有的文档实现了不同偏移量的功能原文链接地址:mysql的lag和Lead函数
本文对比了hive和MySQL实现该功能的方式:
Hive实现方法
PS :空值处设置为NULL
select*
from(selectorders as col_0,lead(orders, 1) over() as col_1,lead(orders 2) over() as col_2,lead(orders, 3) over() as col_3,lead(orders, 4) over() as col_4,lead(orders, 5) over() as col_5,lead(orders, 6) over() as col_6,lead(orders, 7) over() as col_7,lead(orders, 8) over() as col_8fromt) t
Mysql实现方法
PS :空值处设置为NULL
selectt.dt,@lagfield:= @lagfield1 as col_1,@lagfield1:= @lagfield2 as col_2,@lagfield2:= @lagfield3 as col_3,@lagfield3:= @lagfield4 as col_4,@lagfield4:= @lagfield5 as col_5,@lagfield5:= @lagfield6 as col_6,@lagfield6:= @lagfield7 as col_7,@lagfield7:= @lagfield8 as col_8,@lagfield8:= @lagfield9 as col_9,@lagfield9:= orders as orders
fromt,(select@lagfield:= null,@lagfield1:= null,@lagfield2:= null,@lagfield3:= null,@lagfield4:= null,@lagfield5:= null,@lagfield6:= null,@lagfield7:= null,@lagfield8:= null,@lagfield9:= null) init;
运行结果如下图:
这篇关于mysql/hive实现lead()不同偏移量数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!