sql SQL Server 2012 TSQL新函数LAG,LEAD,FIRST_VALUE和LAST_VALUE

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql SQL Server 2012 TSQL新函数LAG,LEAD,FIRST_VALUE和LAST_VALUE相关的知识,希望对你有一定的参考价值。

SELECT [Name]
      ,[Subject]
      ,[Score]
      ,LAG(Score, 1, 0) Over (Partition By Name Order By Subject) As [LagValue]
      ,LEAD(Score, 1, 0) Over (Partition By Name Order By Subject) As [LeadValue]
      ,FIRST_VALUE(Score) Over (Partition By Name Order By Subject) As [FirstValue]
      ,LAST_VALUE(Score) Over (Partition By Name Order By Subject) As [LastValue]
  FROM [Test].[dbo].[Score]

以上是关于sql SQL Server 2012 TSQL新函数LAG,LEAD,FIRST_VALUE和LAST_VALUE的主要内容,如果未能解决你的问题,请参考以下文章

sql tsql__get_server_and_client_ip_info.sql

tsql 实用程序 (FreeTDS) 可以连接到 SQL Server,但 pymssql 不能

TSQL / SQL-SERVER:如何在具有主键的快照复制中查找所有表

TSQL:如何将本地时间转换为 UTC? (SQL Server 2008)

sql server2008 字符串的替换

TSQL - 对象或列名丢失或为空.. 尝试将 sql server 数据库备份到磁盘时