SQL SERVER LEAD和LAG函数
sql server中LEAD和LAG函数可直接获取当前数据上下相邻多少行数据。见以下案例:
--测试数据
if not object_id(N'Tempdb..#T') is null drop table #T
Create table #T([Id] int,[Value] int)
Insert #T
select 1,10 union all
select 2,20 union all
select 3,30 union all
select 4,40 union all
select 5,50
结果如图:
语法以LEAD为例:LEAD ( scalar_expression [ ,offset ] , [ default ] ) OVER ( [ partition_by_clause ] order_by_clause ),读取的数据,偏移多少行,如果没有值默认值是多少
SELECT *,
LEAD(Value, 1, 666) OVER (ORDER BY Value) AS LEADVALUE, --提前1行,默认值666
LAG(Value, 2, 888) OVER (ORDER BY Value) AS LAGVALUE --滞后2行,默认值888
FROM #T;
结果如下:
SQL SERVER LEAD和LAG函数相关推荐
- SQL Server中的LAG函数与LEAD函数介绍
点击上方SQL数据库开发,关注获取SQL视频教程 SQL专栏 SQL数据库基础知识汇总 SQL数据库高级知识汇总 SQL Server从2012版本开始,引入了LEAD和LAG函数,这两个函数可以把之 ...
- SQL SERVER中LEAD和LAG函数
SQL SERVER中LEAD和LAG函数 LEAD和LAG函数 LEAD 访问相同结果集的后续行中的数据,而不使用 SQL Server 2012 中的自联接. LEAD 以当前行之后的给定物理偏移 ...
- percent sql_使用SQL Server中的PERCENT_RANK函数计算SQL百分位数
percent sql This article explores the SQL Server PERCENT_RANK analytical function to calculate SQL P ...
- Oracle 利用lead、lag函数查询已有记录的下一条、上一条记录
(一)函数介绍(lead和lag函数类似) 语法结构: lead(value_expr [,offset][,default]) over([query_partition_clause] order ...
- SQL Server中的STRING_SPLIT函数
This article will cover the STRING_SPLIT function in SQL Server including an overview and detailed u ...
- 学习SQL:SQL Server日期和时间函数
So far, we haven't talked about SQL Server date and time functions. Today we'll change that. We'll t ...
- 什么是SQL Server GETDATE()函数?
Hey, readers! In our previous article, we had understood the working of SQL Server DATEPART() functi ...
- 什么是SQL Server TRIM()函数?
Hello, readers. In today's article, we will be focusing on SQL Server TRIM() function in detail. 您好, ...
- coalesce函数_什么是SQL Server COALESCE()函数?
coalesce函数 Hey, folks! In this article, we will be focusing on SQL Server COALESCE() function. 嘿伙计! ...
最新文章
- android5.0后新特性修改标题头,Android5.0中Material Design的新特性
- oracle选择外键列,Oracle外键列上是否需要索引?
- C语言学习:%d、2d、02d、.2d的区别
- 终极解密输入网址按回车到底发生了什么?
- Bootstrap 表格行的样式
- Typora 快捷键设置
- 自动启动和关闭Oracle 脚本
- 【译】jquery基础教程(jQuery Fundamentals)——(第一部分)概述
- 迅 捷PDF编辑器去水印
- Java职业规划(职业晋升路线、技术转移路线、工作经验与技术栈的匹配)——学习笔记
- lisp 图层字体式样替换_ps将不同图层字体修改成相同字体的方法
- 网站关键词密度设置与优化
- Segmentation笔记4-Boundary-Aware Network for Fast and High-Accuracy Portrait Segmentation
- 2017年7月最新全国行政规划数据库
- R语言二手车汽车销售数据可视化探索:预处理、平滑密度图、地理空间可视化(带自测题)
- 怎样伪原创视频 如何查看视频的md5
- copa文件服务器,Copa
- CISP-信息安全保障-信息安全保障基础
- 土地报备坐标文件(TXT)生成
- 个人整理的 Windows 下 .NET 开发必装的软件