Mysql 5.7 вложенный запрос на выборку выдает ошибку, когда
Unknown column 'CRoute.ID' in 'where clause'
Это мой запрос
SELECT CTrip.ID, CRoute.Name,
(SELECT COUNT(StudentID) FROM CRouteStudent WHERE CRoute.ID = CRouteStudent.RouteID) AS ExpectedStudents,
(SELECT COUNT(*) FROM (SELECT COUNT(*) FROM CRouteStudent WHERE CRoute.ID = CRouteStudent.RouteID GROUP BY Stop) as a) AS ExpectedStops
FROM `CTrip`
JOIN `CRoute` ON `CRoute`.`ID` = `CTrip`.`RouteID`
JOIN `CRouteSchedule` ON `CRouteSchedule`.`RouteID`=`CTrip`.`RouteID`
WHERE `CTrip`.`Direction` = '1'
LIMIT 30
ExpectedStudents работает, ошибка выброса ExpectedStops
ПРИМЕЧАНИЕ. Этот запрос работает в mysql 8.0
.