只选择一个具有最大日期时间的行


SELECT     v.DoorNo,v.NewDoorNo, v.GarageName, c.VersionDate, v.OperatorName as Operator, v.OperatorId, c.DeviceId, c.VehicleId, c.ProgramVersionNo, 
                  c.ParameterFileVersionNo, c.TariffFileVersionNo, c.BlaclistFileVersionNo, c.LineNoFileVersionNo, c.ScreenProgramVersion, 
                  c.SoapProgramVersiyon
FROM         dbo.vValidator AS v RIGHT JOIN
                  dbo.CDeviceVersion AS c  with(nolock) ON (v.DoorNo = c.DoorNo
                                or v.NewDoorNo=c.DoorNo
                                                          where v.NewDoorNo='O1211'

此查询返回2行,但我只想选择一行具有最大版本日期。如何选择?

这就是您想要的吗?

SELECT  TOP (1) v.DoorNo,v.NewDoorNo, v.GarageName, c.VersionDate, v.OperatorName as Operator, v.OperatorId, c.DeviceId, c.VehicleId, c.ProgramVersionNo, 
                  c.ParameterFileVersionNo, c.TariffFileVersionNo, c.BlaclistFileVersionNo, c.LineNoFileVersionNo, c.ScreenProgramVersion, 
                  c.SoapProgramVersiyon
FROM         dbo.vValidator AS v RIGHT JOIN
                  dbo.CDeviceVersion AS c  with(nolock) ON (v.DoorNo = c.DoorNo
                                or v.NewDoorNo=c.DoorNo)
                                                          where v.NewDoorNo='O1211'
 ORDER BY c.VersionDate

相关内容

  • 没有找到相关文章