我有一張表,我需要從一個組中獲取最早的日期並能夠返回所有行。我很難找到它,因爲我需要返回system_id字段。如何查找組中最早的日期
AssignedProfsHistory MatterID EffectiveDate
1 33434-3344 08/22/2005
2 33434-3344 07/12/2004
3 33434-3344 07/12/2004
4 21122-323 12/05/2007
5 43332-986 10/18/2014
6 43332-986 03/23/2013
所以在這個例子中,SYSTEMID 2 & 3行應返回,因爲它們都被用於最早日期。 systemid 4的行應返回並返回systemid 6。
這是我到目前爲止。因爲我需要包含systemid(AssignedProfHistory),所以我沒有得到我需要的結果。
SELECT aph.AssignedProfsHistory,
m.MatterID,
Min(aph.EffectiveDate) as 'EffectiveDate'
from AssignedProfsHistory aph
INNER JOIN Matters m
ON aph.Matters = m.Matters
WHERE aph.AssignedType = 'Originating'
Group by m.matters,m.matterid,aph.assignedprofshistory
order by m.MatterID
任何想法如何獲得我需要的結果?
預先感謝您。
這個腳本適用於我。謝謝! – user3119773