DECLARE @TestData TABLE(
ID INT IDENTITY(1,1),
Department VARCHAR(20),
LastName VARCHAR(20),
Rate FLOAT
)
INSERT INTO @TestData(Department,LastName,Rate)
SELECT 'Document Control','Arifin',17.7885 UNION ALL
SELECT 'Document Control','Norred',16.8269 UNION ALL
SELECT 'Document Control','Kharatishvili',16.8269 UNION ALL
SELECT 'Information Services','Chai',10.25 UNION ALL
SELECT 'Information Services','Berge',10.25 UNION ALL
SELECT 'Information Services','Trenary',50.4808 UNION ALL
SELECT 'Information Services','Conroy',39.6635 UNION ALL
SELECT 'Information Services','Ajenstat',38.4615 UNION ALL
SELECT 'Information Services','Wilson',38.4615 UNION ALL
SELECT 'Information Services','Connelly',32.4519 UNION ALL
SELECT 'Information Services','Meyyappan',32.4519
SELECT * FROM @TestData
这里以Department分区,则整个数据集被分成了两部分:Information Services和Document Control两块,这时FIRST_VALUE分别返回两块分区内的首条数据值,同样的受ORDER BY关键字的影响,
与FIRST_VALUE函数同时出现的还有一个,SECOND_VALUE?NO,没有这个函数啊,但是有一LAST_VALUE,怎么函数怎么使用,不打算再单独起一篇文章了,LAST_VALUE嗯