【发布时间】:2023-03-19 13:11:01
【问题描述】:
我一直在 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 有某种变化,不允许我在子查询中使用列,但我找不到关于该主题的任何内容。
有没有人有这方面的经验,或者任何人都可以提出一种我正在努力完成的工作的方法吗?
【问题讨论】:
-
您是否尝试过仅使用
BusDestinationStations.Dayofset是否有效? -
它在不同的查询中工作,但在这个查询中使用它意味着表的另一个实例,这不是我想要完成的。即便如此,它也不适用于“BusDestinationStations” - 它在“where 子句”中显示未知列“BusDestinationStations.DayOfset”
-
一旦我将它粘贴到 mysql 上,它会给我一个 sql 语法错误
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) -
尝试使用这个查询
-
结果是一样的