我正在使用 SQLServer2008。
我的存储过程的输出是:
--------------------------------------------------------
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
但它仍然显示错误的结果...请帮助我..我错在哪里?谢谢。