开发者社区> 问答> 正文

无法在SQL Server中执行分组依据

需要唯一具有最大BookingVersion 分组依据的行 shipmentNumber, shipmentDate,

elect max(BookingVersion) BookingVersion, flightId, shipmentNumber, shipmentDate, FlightOffPoint, IIF(BookingStatusCode = 'XX', 'XX','SS') BookingStatusCode
from Exp_BookingDelta where flightid='625436' 
group by flightId, shipmentNumber, shipmentDate, FlightOffPoint, BookingStatusCode  
order by max(BookingVersion) desc

谁能解释我所缺少的吗?

当前结果:

BookingVersion  flightId    shipmentNumber  shipmentDate    FlightOffPoint  BookingStatusCode
4               625436      61823647238     2019-12-04      LHR             XX
2               625436      61823647238     2019-12-04      LHR             SS
1               625436      61826374895     2019-12-06      LHR             XX
0               625436      61825364780     2019-11-26      LHR             SS
0               625436      61825364791     2019-11-26      LHR             SS
0               625436      61825364802     2019-11-26      LHR             SS
0               625436      61826374895     2019-12-06      LHR             SS

预期结果:

BookingVersion  flightId    shipmentNumber  shipmentDate    FlightOffPoint  BookingStatusCode
4               625436      61823647238     2019-12-04      LHR             XX
1               625436      61826374895     2019-12-06      LHR             XX
0               625436      61825364780     2019-11-26      LHR             SS
0               625436      61825364791     2019-11-26      LHR             SS
0               625436      61825364802     2019-11-26      LHR             SS

展开
收起
心有灵_夕 2019-12-06 23:05:29 622 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
SQL Server 2017 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载