SELECT t2.*,t1.AbnormalCount,count(*) as TotalCount,(1- t1.AbnormalCount/count(*)) as NormalRate
FROM
( SELECT *
FROM `FlightOnTime`.`FlightOnTime`
WHERE (`FlightDate` BETWEEN '2016-04-01' AND '2016-04-14')
AND `DepAP` IN (SOMETHING)AND `Reg` IN (SOMETHING)
ORDER BY `FlightDate` DESC
)t2,
( SELECT FlightNo,DepAP,ArrAP,count(*) as AbnormalCount
FROM `FlightOnTime`.`FlightOnTime`
WHERE (`FlightDate` BETWEEN '2016-04-01' AND '2016-04-14')
AND `normalFlag` = -1
AND `DepAP` IN (SOMETHING)AND `Reg` IN (SOMETHING))t1
WHERE t2.`FlightNo` = t1.`FlightNo`
AND t2.`DepAP`=t1.`DepAP`
AND t2.`ArrAP`=t1.`ArrAP`
GROUP BY t2.`FlightNo`,t2.`DepAP`
ORDER BY `NormalRate`,t2.`FlightNo`
sorry for the format of the sql . because this sql is not type by myself but build in my program and miss a ")" after copy.
SOMETHING is a array of string , i replae with SOMETHING for readable .
I test last night with a mysql 5.6.28 installed from mysql installer.
it work fine .
SO , the question now is the verision between 5.6 and 5.7 .