SELECT a.id
,a.cnname
,b.personid
,Row_number() OVER(partition BY personid ORDER BY releasetime DESC) num
,releasetime
from ent_movie a
LEFT JOIN ent_movie_relate_person b ON a.id = b.movieid
WHERE a.typeid=1 and a.cnName is not null and a.cnName!=''
AND b.professionid = 1
and a.releaseTime>=DATEADD(YY,-3,GETDATE()) and a.releaseTime<=GETDATE()
語法形式:ROW_NUMBER() OVER(PARTITION BY COL1 ORDER BY COL2)
解釋:根據COL1分組,在分組內部根據 COL2排序,而此函數計算的值就表示每組內部排序後的順序編號(組內連續的唯一的)
參考學習:http://www.jb51.net/article/29162.htm