我不确定解释这个的最好方法,但我有一份机场清单。我希望能够获取该机场列表并使用这些信息列入往返这些机场的定期航班列表。这是我到目前为止所做的:
DROP FUNCTION IF EXISTS GreaterCircleNm;
DELIMITER go
CREATE FUNCTION GreaterCircleNm( lat1 FLOAT, lon1 FLOAT, lat2 FLOAT, lon2 FLOAT ) RETURNS float
BEGIN
DECLARE pi, q1, dist FLOAT;
SET pi = PI();
SET lat1 = lat1 * pi / 180;
SET lon1 = lon1 * pi / 180;
SET lat2 = lat2 * pi / 180;
SET lon2 = lon2 * pi / 180;
SET q1 = ACOS(sin(lat1)*sin(lat2)+COS(lat1)*COS(lat2)*COS(lon1-lon2));
SET dist = q1*180*60/pi;
RETURN dist;
END;
go
DELIMITER ;
INSERT INTO phpvms_schedules (depicao, arricao, distance)
SELECT
depart.icao,
arrive.icao,
ROUND(GreaterCircleNm(depart.lat,depart.lng,arrive.lat,arrive.lng),2) as Nm
FROM phpvms_airports AS depart
INNER JOIN phpvms_airports AS arrive ON depart.icao <> arrive.icao
我被困在下一步去哪里。我尝试运行代码时也遇到此错误:
1452 - 无法添加或更新子行:外键约束失败(
virtu259_phpvms
。phpvms_schedules
,CONSTRAINTphpvms_schedules_ibfk_1
FOREIGN KEY(code
)参考phpvms_airlines
(code
)ON UPDATE CASCADE)
答案 0 :(得分:0)
约束phpvms_schedules_ibfk_1要求您为列代码输入的值已存在于列代码中的virtu259_phpvms.phpvms_airlines表中。
SELECT * FROM virtu259_phpvms.phpvms_airlines WHERE code='?'
这个结果与第一张表中的结果一致吗?