0

当我添加列“AVAILABILITY”时,我的查询不断返回同一设备的 ONRENT 和 CLOSED 的最后日期。我只想要每件设备的最后一个条目。

这是我的查询:

select      max([No_]), [Start Date], [Availability Status]
from        [Rental Line]
group by    [No_], [Start Date], [Availability Status]
4

2 回答 2

0
select      max([No_]), [Start Date], [Availability Status]
from        [Rental Line]
group by    [No_], [Start Date], [Availability Status]
order by    [AVAILABILITY] DESC
于 2013-10-14T15:16:44.387 回答
0

如果我正确理解您的问题,您只需要 No_ 定义的每件设备的最后可用性状态,其中“最后”将由最晚开始日期定义。如果是这样,这应该工作:

试试这个:

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]
于 2013-10-14T15:34:20.227 回答