GROUP BY中的SQL Server 2014 LAST_VALUE

时间:2015-03-13 11:00:26

标签: sql-server sql-server-2014 window-functions

是否可以在LAST_VALUE select语句中使用GROUP BY关键字?

SELECT colA, 
       LAST_VALUE(colB) 
            OVER (PARTITION BY ... ORDER BY ... ROWS BETWEEN ...) 
FROM MyTable 
GROUP BY colA

1 个答案:

答案 0 :(得分:0)

我不认为window功能可用于group by。可能sub-select将完成工作

select colA,L_values
from
(
SELECT colA, 
       LAST_VALUE(colB) 
            OVER (PARTITION BY ... ORDER BY ... ROWS BETWEEN ...) L_Value
FROM MyTable
) a
group by colA,L_values