有人可以幫我看看這個查詢嗎?選擇多列一組?
SELECT CLIENT.ID_CLIENT ,
EVALUATION_CLIENT.ID_EVAL ,
MAX(EVALUATION_CLIENT.Date) AS DATE
FROM EVALUATION_CLIENT
INNER JOIN CLIENT
ON CLIENT.ID_CLIENT = EVALUATION_CLIENT.FK_IDClient
WHERE EVALUATION_CLIENT.Date
BETWEEN @START_DATE_LOCAL
AND @END_DATE_LOCAL
GROUP BY CLIENT.IDCLIENT,
EVALUATION_CLIENT.ID_EVAL
它返回......
ID_CLIENT | ID_EVAL | DATE_EVAL
1423 |11160 | 2008-02-12 00:00:00.000
1423 |11161 | 2008-02-18 00:00:00.000
18 |11162 | 2008-02-15 00:00:00.000
666 |11163 | 2008-02-19 00:00:00.000
但我想是這樣(不重複的客戶端)
ID_CLIENT | ID_EVAL | DATE_EVAL
1423 |11161 | 2008-02-18 00:00:00.000
18 |11162 | 2008-02-15 00:00:00.000
666 |11163 | 2008-02-19 00:00:00.000
我使用MSSQL 2008
感謝了很多!
更新:我需要Id_Eval爲最近的日期由Id_client
你只是想爲每個客戶提供最高的ID_EVAL嗎?或者你想要最新的日期?這些定義是否一樣? – 2011-04-20 18:32:38