0

我在尝试通过文档类型名称获取最小日期时遇到问题,它会提取最小日期并将相同的值应用于两个值。所以我有一个订单,作为预订确认和预订确认,我需要两者的最小创建日期作为它们的唯一日期......有没有一种简单的方法来调整下面的代码?当前数据

订单号 文档类型 预订确认上传
403455 BKG AKN 2021-04-15T14:09:14
403455 BKG CNFM 2021-04-15T14:09:14
403455 BKG CNFM 2021-04-15T14:09:14

成为数据

订单号 文档类型 预订确认上传
403455 BKG AKN 2021-04-15T14:09:14
403455 BKG CNFM 2021-04-17T09:39:10

所有代码

select orderId,team,DocType,workgroups,status,carrier,

TIMESTAMPDIFF(MINUTE,bookingRequest,bookingConfirmationUploaded)/60.0 as 'startToFinish(HRs)', bookingRequest, bookingConfirmationUploaded, Origin, POL_code, POD_code, Destination, Containertype, Qty, Departure

from ( 选择 orderId, team, DocType, workgroups, status, carrier, bookingRequest, bookingConfirmationUploaded, Origin, POL_code, POD_code, Destination, Containertype, Qty, Departure from (

SELECT CAST( Order.AS idCHAR CHARACTER SET utf8) AS orderId, Org. name作为团队, Order. status,(从组织中选择名称,其中 id = Voyage.carrierId)作为运营商, Order.createdAt 作为预订请求,

(选择 min(Document.createdAt) 作为 bookingConfirmationUploaded fromDocument

.orgDocumentTypeId = .id 和.nameOrgDocumentType上的内部连接​​('Booking Confirmation','Booking Acknowledgment')DocumentOrgDocumentTypeOrgDocumentType

其中Document.orderId = Order.id) 作为 bookingConfirmationUploaded, OrgDocumentType.name 作为 ' QuoteCriteriaDocType',.Containertype 作为 Containertype, .QuantityOrder作为 Qty, QuoteCriteria.Fromaddress 作为'Origin',. QuoteCriteriaFromportcode 作为'POL_code',. QuoteCriteriaToAddress 作为'Destination',. QuoteCriteriaToportcode作为'POD_code',concat(日期(QuoteCriteria.Estimateddate),'')作为'出发',

if( Voyage. originAtdis not null, Voyage. originAtd, Voyage. originEtd)AS shippingDate, CONCAT('[', _workgroup.name, ']') As Workgroups FROM Order join Orgon(( Order. orgId= Org. id)) left join Voyageon(( Order. selectedVoyageId= Voyage. id)) left join QuoteCriteriaon(( Order. id= QuoteCriteria. orderId)) left join Documenton(( Order. id= Document. OrderId)) left join OrgDocumentTypeon Document.orgDocumentTypeId = OrgDocumentType.id LEFT JOIN OrderWorkgroup _orderWorkgroup ON Orderid=_orderWorkgroup.orderId 左加入工作组 _workgroup ON _workgroup.id = _orderWorkgroup.workgroupId WHERE Orgname像 'Yara%' 和Order. status不像OrgDocumentType('2517','2154') 中的 'CANCELLED%' 和 .id 和 ('Porsgrunn Plant','Porsgrunn Plant-','BUMA','BUMA-') 中的 _workgroup.name 和 Order.createdAt >= convert_tz('2021-04-15 00:00:00.000', 'UTC', @@session.time_zone)

) tmp2
) tmp3 order by bookingRequest;
4

0 回答 0