2015-03-13 153 views
1

是否可以在GROUP BY select語句中使用LAST_VALUE關鍵字?SQL Server 2014 LAST_VALUE GROUP BY

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

請更好地解釋你的問題,目前還不清楚你在問什麼。 – Tanner 2015-03-13 11:10:50

+0

確保你不會因爲這個http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – Mihai 2015-03-13 11:29:29

回答

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