Hive 窗口函数之 lead() over(partition by ) 和 lag() over(partition by )
lead函数用于提取当前行前某行的数据
lag函数用于提取当前行后某行的数据
语法如下:
lead(expression,offset,default) over(partition by ... order by ...)
lag(expression,offset,default) over(partition by ... order by ... )
例如提取前一周和后一周的数据,如下:
select
year,week,sale,
lead(sale,1,NULL) over(--前一周sale partition by product,country,region order by year,week) lead_week_sale,
lag(sale,1,NULL) over(--后一周sale partition by product,country,region order by year,week) lag_week_sale
from sales_fact a
where a.country='country1' and a.product='product1' and region='region1'
order by product,country,year,week
实例2:
SELECT
created_at create_time,
operator,
bridge_duration,
lead(created_at, 1) OVER (PARTITION BY operator ORDER BY created_at ASC) next_create_time
FROM ods.ods_call_ctob_auction_call_recording
WHERE substr(created_at,1,10)= '${date_y_m_d}'
————————————————
版权声明:本文为CSDN博主「hongyd」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/hongyd/article/details/83056194
最新文章
- kd树和knn算法的c语言实现
- C++ 16进制转10进制
- PL/Sql 中创建、调试、调用存储过程
- scrapy使用爬取多个页面
- 【转】qtp-learn
- java基础(死循环退出选项)
- Nodejs in Visual Studio Code 08.IIS
- WOT2016大数据技术峰会——千人技术盛宴
- 限制容器的 Block IO - 每天5分钟玩转 Docker 容器技术(29)
- 快速排序Golang版本
- tensorflow rnn 最简单实现代码
- Exp5 MSF基础应用 20164302 王一帆
- MS SQL Server 数据库连接字符串详解
- mysql 安装问题三:FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper
- s21day06 python笔记
- 【git】一台机器上使用不同的git账号
- Vakuum开发笔记01 开天辟地
- 【LOJ6089】小Y的背包计数问题(动态规划)
- python线程进程
- 各种HTTPS站点的SSL证书 ,扩展SSL证书,密钥交换和身份验证机制汇总
热门文章
- org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.NumberFormatException: For input string: ";W%"; ### Cause: java.lang.NumberFormatException: For input s
- 关于toString()和valueOf()以及Object.prototype.toString.call()的结合理解
- Kosaraju算法 有向图的强连通分量
- SCAU 2015 GDCPC team_training1
- 网页中<;a>;标签新窗口和location.href 新窗口打开
- C# 委托 多线程
- 解决本地mysql服务允许被外部主机连接
- glibc2.22
- 2018-2-13-Windows-10-16251-添加的-api
- Unity 官网无法访问|国外网站访问过慢|国外网站访问加速器