我有这样的SQL:SQL:子与日期选择
Select history.date, history.rasID, status.status
From RAS_RASHistory as history
inner join RAS_Status as status on History.statusID = status.statusID
Where history.date between @startDate
and @endDate and history.statusID in (select value from @status)
order by rasID, history.date desc
当我执行它,我得到这些结果:
date rasID status
2011-11-17 14:15:21.693 10000 Planning
2011-11-17 14:14:53.177 10000 New
2011-11-16 08:39:47.770 10000 New
2011-11-16 09:18:50.630 10001 New
2011-11-16 11:26:23.867 10002 Planning
2011-11-16 10:01:42.050 10002 Planning
2011-11-16 10:00:36.527 10002 New
我真正想要的是这样的:
date rasID status
2011-11-17 14:15:21.693 10000 Planning
2011-11-16 09:18:50.630 10001 New
2011-11-16 11:26:23.867 10002 Planning
但我不确定如何去得到它。我认为可能是一种选择,但我不太确定。有人能指引我朝着正确的方向吗?
因此,获得最新的日期为每个'rasID',然后获取最新的'status' – Kermit
需要更好地制定的要求。对于每个rasId条目你想要最近的状态。那是对的吗? – Brian
是的,我想要最近的状态。 –