当我添加“AVAILABILITY”列时,我的查询会为同一件设备返回ONRENT和CLOSED的最后日期。我只想要每件设备的最后一个条目。
这是我的问题:
select max([No_]), [Start Date], [Availability Status]
from [Rental Line]
group by [No_], [Start Date], [Availability Status]
答案 0 :(得分:0)
select max([No_]), [Start Date], [Availability Status]
from [Rental Line]
group by [No_], [Start Date], [Availability Status]
order by [AVAILABILITY] DESC
答案 1 :(得分:0)
如果我正确理解您的问题,您只需要No_定义的每件设备的最后可用状态,其中“last”将由最新的开始日期定义。如果是这样,这应该有效:
试试这个:
select RL.[No_], RL.[Start Date], RL.[Availability Status]
from [Rental Line] RL
join
(
select
No_,
MAX([Start Date]) AS [LastStartDate]
from [Rental Line] RL1
group by No_
) X on RL.No_ = X.No_ AND RL.[Start Date] = X.[LastStartDate]