示例表:TSQL獲得最大和最小日期一個單獨的,但不是唯一的記錄
test_date | test_result | unique_ID
12/25/15 | 100 | 50
12/01/15 | 150 | 75
10/01/15 | 135 | 75
09/22/14 | 99 | 50
04/10/13 | 125 | 50
我需要找到第一和最後一個測試日期以及測試結果通過用戶匹配所述的日期。所以,我可以按ID分組,但不能測試結果。
SELECT MAX(test_date)[need matching test_result],
MIN(test_date) [need matching test_result],
unique_id
from [table]
group by unique_id
謝謝!
你應該包括你的願望輸出。 –