子查询问题 MySQL 5.5 vs 5.6

Issue with a subquery MySQL 5.5 vs 5.6

我一直是 运行 MySQL 5.5 (percona) 上的一个网站并使用这个查询,它有效:

SELECT
    bds.FromStationPositionID
FROM
    BusDestinationSegments AS bds
LEFT JOIN BusDestinationSegmentPrices AS bdsp ON bds.SegmentID = bdsp.BusDestinationSegmentID
AND EXISTS (
    SELECT
        BusDestinationScheduleID
    FROM
        BusDestinationSchedule
    WHERE
        BusDestinationScheduleDate + INTERVAL bdssf.DayOfset DAY = '2016-01-26'
),
 BusDestinationStations AS bdssf

我需要升级到 5.6(还是 Percona)所以我就这么做了(在开发服务器上)。 但是,此查询现在不起作用。它告诉我:

[Err] 1054 - Unknown column 'bdssf.DayOfset' in 'where clause'

我应该补充一点,我已经检查过并且该列在那里。

我猜从 5.5 到 5.6 有某种变化不允许我在子查询中使用列,但我找不到任何关于该主题的内容。

有没有人有过这方面的经验,或者有没有人可以建议一种方法使我正在努力完成的工作可行?

您似乎混合使用了新旧 JOIN 语法。并期望 BusDestinationStations(DayOfset 列来自 bdssf)到 CROSS JOIN。

这曾经有效,但 MySQL 5.6 中的变化之一是连接的优先级:-

http://dev.mysql.com/doc/refman/5.6/en/join.html :-

Previously, the comma operator (,) and JOIN both had the same precedence, so the join expression t1, t2 JOIN t3 was interpreted as ((t1, t2) JOIN t3). Now JOIN has higher precedence, so the expression is interpreted as (t1, (t2 JOIN t3)). This change affects statements that use an ON clause, because that clause can refer only to columns in the operands of the join, and the change in precedence changes interpretation of what those operands are.

所以我认为正在发生的事情是 MySQL 试图在隐式连接到 BusDestinationStations 之前执行子查询的处理,因此它对 bdssf.DayOfset 一无所知当执行子查询时。

认为以下等同于您正在尝试做的事情:-

SELECT bds.FromStationPositionID
FROM BusDestinationSegments AS bds
CROSS JOIN BusDestinationStations AS bdssf
LEFT JOIN BusDestinationSegmentPrices AS bdsp ON bds.SegmentID = bdsp.BusDestinationSegmentID
AND EXISTS 
(
    SELECT BusDestinationScheduleID
    FROM BusDestinationSchedule
    WHERE BusDestinationScheduleDate + INTERVAL bdssf.DayOfset DAY = '2016-01-26'
)

(虽然我有点怀疑做这样的交叉连接只是为了获取子查询的值 - 看起来效率很低)。