2017-06-01 70 views

回答

2

一種方法是:

select t.* 
from (select t.*, 
      row_number() over (partition by grp order by col) as seqnum 
     from t 
    ) t 
where seqnum <= @n; 
0

它的一件容易的事

MAX(column) OVER(PARTITION BY column) AS mx 

您將獲得每個列的值,這是TOP N

最大值

用其他集合函數替換MAX以獲得另一個洞察,如MIN,AVG等。