我正在使用SQLServer2008。我的存儲過程的按ID組合記錄
輸出是:
--------------------------------------------------------
BrokerCode | MemberId | FY | SY | TY |
--------------------------------------------------------
104 | 24 | 1140 | 0.00 | 0.00 |
--------------------------------------------------------
104 | 24 | 1140 | 570 | 0.00 |
--------------------------------------------------------
104 | 30 | 500 | 0.00 | 0.00 |
--------------------------------------------------------
104 | 30 | 500 | 360 | 0.00 |
--------------------------------------------------------
我想造成這樣的:
--------------------------------------------------------
BrokerCode | MemberId | FY | SY | TY |
--------------------------------------------------------
104 | 24 | 1140 | 570 | 0.00 |
--------------------------------------------------------
104 | 30 | 500 | 360 | 0.00 |
--------------------------------------------------------
所以,我已經嘗試使用:
WITH CTE AS (
SELECT BrockerCode,
MemberId,
RN=ROW_NUMBER()OVER(PARTITION BY MemberId ORDER BY MemberID),
FY=MIN(FY)OVER(PARTITION BY MemberId),
SY=MIN(SY)OVER(PARTITION BY MemberId),
TY=MIN(TY)OVER(PARTITION BY MemberId)
FROM @tablePromotee)
SELECT MemberId,BrockerCode,FY,SY,TY FROM CTE WHERE RN = 1
但仍顯示錯誤結果...請幫助我..我錯了嗎?謝謝。
不應該是'FY = MAX(FY)OVER(PARTITION BY MemberId)'而不是'MIN'? – praveen 2013-04-24 05:54:31