在 MySQL 中使用 INNER JOIN 选择多个表?
我有一个收集一组特定数据的网站。这是一个旅行社网站。有必要确定住宿是否仍然可以预订。当我不选择任何搜索过滤器(如目的地、分类、设施等)时,我会得到一个有效的查询。看起来像:
SELECT `accommodation` . *
FROM `accommodation`
INNER JOIN (
SELECT `fk_accommodation` , MAX( `dateuntil` ) - ( `releasedays` *60 *60 *24 ) AS `LatestBookableTimestamp`
FROM `priceperiod`
GROUP BY `fk_accommodation`
) AS `pp` ON ( `pp`.`fk_accommodation` = `accommodation`.`id` )
WHERE `pp`.`LatestBookableTimestamp` > UNIX_TIMESTAMP( )
AND `accommodation`.`fk_country` <>0
AND `accommodation`.`classification` >=0
AND `accommodation`.`type` = 'Z'
但是当我选择一个过滤器(在本例中是“目标”过滤器(儿童、活动、休息、冬季运动等)时,我收到查询:
SELECT `accommodation` . *
FROM `accommodation` , `link_at`
INNER JOIN (
SELECT `fk_accommodation` , MAX( `dateuntil` ) - ( `releasedays` *60 *60 *24 ) AS `LatestBookableTimestamp`
FROM `priceperiod`
GROUP BY `fk_accommodation`
) AS `pp` ON ( `pp`.`fk_accommodation` = `accommodation`.`id` )
WHERE `pp`.`LatestBookableTimestamp` > UNIX_TIMESTAMP( )
AND `accommodation`.`fk_country` <>0
AND `link_at`.`fk_target`
IN ( 10, 2 )
AND `link_at`.`fk_accommodation` = `accommodation`.`id`
AND `accommodation`.`classification` >=0
AND `accommodation`.`type` = 'Z'
现在,当我执行此查询时,我收到错误:#1054 -“on 子句”中的未知列“accommodation.id”
我认为这是因为 FROM 子句中使用了另一个表。有人知道在查询多个表时如何使用 INNER JOIN 吗?
I have a site where a specific set of data is collected. This is a travel agency website. It is neccesary to determine whether or not an accommodation is still bookable. When I don't select any searchfilters (like destination, classification, facilities etc) I get a working query. The looks like:
SELECT `accommodation` . *
FROM `accommodation`
INNER JOIN (
SELECT `fk_accommodation` , MAX( `dateuntil` ) - ( `releasedays` *60 *60 *24 ) AS `LatestBookableTimestamp`
FROM `priceperiod`
GROUP BY `fk_accommodation`
) AS `pp` ON ( `pp`.`fk_accommodation` = `accommodation`.`id` )
WHERE `pp`.`LatestBookableTimestamp` > UNIX_TIMESTAMP( )
AND `accommodation`.`fk_country` <>0
AND `accommodation`.`classification` >=0
AND `accommodation`.`type` = 'Z'
But when I select a filter (in this case a 'target' filter (children, active, rest, wintersports etc) I get the query:
SELECT `accommodation` . *
FROM `accommodation` , `link_at`
INNER JOIN (
SELECT `fk_accommodation` , MAX( `dateuntil` ) - ( `releasedays` *60 *60 *24 ) AS `LatestBookableTimestamp`
FROM `priceperiod`
GROUP BY `fk_accommodation`
) AS `pp` ON ( `pp`.`fk_accommodation` = `accommodation`.`id` )
WHERE `pp`.`LatestBookableTimestamp` > UNIX_TIMESTAMP( )
AND `accommodation`.`fk_country` <>0
AND `link_at`.`fk_target`
IN ( 10, 2 )
AND `link_at`.`fk_accommodation` = `accommodation`.`id`
AND `accommodation`.`classification` >=0
AND `accommodation`.`type` = 'Z'
Now when I execute this query I get the error: #1054 - Unknown column 'accommodation.id' in 'on clause'
. I think this is because another table is used in the FROM clausule. Does anyone have an idea on how to use the INNER JOIN when multiple tables are queried?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
完全过滤查询造成的困难......
The difficulity caused by a full filtered query...