我在尝试通过文档类型名称获取最小日期时遇到问题,它会提取最小日期并将相同的值应用于两个值。所以我有一个订单,作为预订确认和预订确认,我需要两者的最小创建日期作为它们的唯一日期......有没有一种简单的方法来调整下面的代码?当前数据
订单号 | 文档类型 | 预订确认上传 |
---|---|---|
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 id
CHAR 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')Document
OrgDocumentType
OrgDocumentType
其中Document
.orderId = Order
.id) 作为 bookingConfirmationUploaded,
OrgDocumentType
.name 作为 '
QuoteCriteria
DocType',.Containertype 作为 Containertype,
.QuantityOrder
作为 Qty,
QuoteCriteria
.Fromaddress 作为'Origin',.
QuoteCriteria
Fromportcode 作为'POL_code',.
QuoteCriteria
ToAddress 作为'Destination',.
QuoteCriteria
Toportcode作为'POD_code',concat(日期(QuoteCriteria
.Estimateddate),'')作为'出发',
if( Voyage
. originAtd
is not null, Voyage
. originAtd
, Voyage
. originEtd
)AS shippingDate, CONCAT('[', _workgroup.name, ']') As Workgroups
FROM
Order
join Org
on(( Order
. orgId
= Org
. id
)) left join Voyage
on(( Order
. selectedVoyageId
= Voyage
. id
)) left join QuoteCriteria
on(( Order
. id
= QuoteCriteria
. orderId
)) left join Document
on(( Order
. id
= Document
. OrderId
)) left join OrgDocumentType
on Document
.orgDocumentTypeId = OrgDocumentType
.id LEFT JOIN OrderWorkgroup _orderWorkgroup ON Order
。id
=_orderWorkgroup.orderId 左加入工作组 _workgroup ON _workgroup.id = _orderWorkgroup.workgroupId WHERE
Org
。name
像 '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;