我只想顯示每個ID的記錄少於10個條目的ID,一個ID可能有幾個值,如下面的數據中所示。我想 我已經嘗試此查詢,但它也選擇了記錄ID 2選擇少於10個條目的記錄sql server
select ID, Name ,LastName ,PaymentDate,POSITION
From (select ID, Name ,LastName ,PaymentDate ,ROW_NUMBER() OVER(PARTITION BY ID ORDER BY PaymentDate DESC) AS POSITION
)
where Position < 10
任何幫助,請
ID Name LastName PaymentDate
1 John Abraham 2015-05-08
1 John Abraham 2014-05-08
1 John Abraham 2013-05-08
1 John Abraham 2012-05-08
1 John Abraham 2011-05-08
1 John Abraham 2010-05-08
------------------------------
2 Adam White 2015-05-08
2 Adam White 2014-05-08
2 Adam White 2013-05-08
2 Adam White 2012-05-08
2 Adam White 2011-05-08
2 Adam White 2010-05-08
2 Adam White 2009-05-08
2 Adam White 2008-05-08
2 Adam White 2007-05-08
2 Adam White 2006-05-08
2 Adam White 2005-05-08
2 Adam White 20004-05-08
非常感謝,如預期般運作良好。我已經完成了這個查詢,子查詢中有一點錯誤。 – Ilyas