假设我们有下表
_________________________________________________________________________
|FlightNo | DepartureDate | Origin | Destination | Flightduration |
_________________________________________________________________________
| IB233 | 2018-12-31 09:30:45 | Berlin | Barcelona | 200 |
| IB222 | 2019-01-01 12:20:34 | Barcelona| Rome | 100 |
| LE111 | 2019-01-01 11:11:11 | Rome | NY | 400 |
__________________________________________________________________________
现在,我想计算纽约目的地和柏林开始之间的时差。 我要检查整个飞行时间是否小于660分钟。
我已经解决了,但是没用..
SELECT
TIMEDIFF(
(SELECT adddate(DepartureDate, INTERVAL FlightDuration
MINUTE)
FROM flightexecution
where ICAO_Code_Origin = 'Berlin'),
(SELECT DepartureDate
FROM flightexecution
where ICAO_Code_Destination = 'NY' AND ICAO_Origin NOT LIKE 'Berlin' AND)
) from flightexecution ;
MySQL的结果只是给我一个“ OK”,这意味着有些错误...
你们能帮我吗?
答案 0 :(得分:1)
您可以尝试像这样的自联接查询
SELECT
A.Origin,
(TIME_TO_SEC(TIME_DIFF(A.DepartureDate, C.DepartureDate))/60 - A.FlightDuration - B.FlightDuration) AS `Transfer time (minutes)`,
A.DepartureDate,
(TIME_TO_SEC(TIME_DIFF(A.DepartureDate, C.DepartureDate))/60 + C.FlightDuration) AS `Overall Duration (minutes)`
FROM
flightexecution A INNER JOIN
flightexecution B
ON A.Destination = B.Origin INNER JOIN
flightexecution C
ON B.Destination = C.Origin
WHERE
A.Origin = 'Berlin'
AND C.Destination = 'NY'