繁体   English   中英

MySQL错误1054:'on子句'中的未知列'hotels.postal_code'

[英]MySQL Error 1054: Unknown Column 'hotels.postal_code' in 'on clause'

我不太清楚为什么,但我的代码似乎无法正常工作。 它要么我得到错误1052或1054.这是我的代码。 请帮忙。

SELECT

    hotels.postal_code AS ' Hotel Postal Code',
    name AS 'Hotel Name',
    latitude AS 'Latitude',
    longitude AS 'Longitude',
    address AS 'Hotel Address',
    hyperlink AS 'Hotel Hyperlink',
    hotels.district AS 'Hotel District',
    'hotel' AS type

FROM
    hotels

        join
    hotel_sales ON hotels.postal_code = hotel_sales.sales_id
        join
    postal_code_location ON hotels.district = postal_code_location.district 

UNION SELECT 

    malls.postal_code AS ' Mall Postal Code',
    name AS 'Mall Name',
    latitude AS 'Latitude',
    longitude AS 'Longitude',
    address AS 'Mall Address',
    hyperlink AS 'Mall Hyperlink',
    malls.district AS 'Mall District',
    'mall' AS type
FROM
malls

        join
    hotel_sales ON hotels.postal_code = hotel_sales.sales_id
        join
    postal_code_location ON hotels.district = postal_code_location.district

更换

FROM
malls

        join
    hotel_sales ON hotels.postal_code = hotel_sales.sales_id

FROM
malls

        join
    hotel_sales ON malls.postal_code = hotel_sales.sales_id

使用右栏加入MALLSHOTEL_SALES ......

所以最终的查询将是......

SELECT

    hotels.postal_code AS ' Hotel Postal Code',
    name AS 'Hotel Name',
    latitude AS 'Latitude',
    longitude AS 'Longitude',
    address AS 'Hotel Address',
    hyperlink AS 'Hotel Hyperlink',
    hotels.district AS 'Hotel District',
    'hotel' AS type

FROM
    hotels

        join
    hotel_sales ON hotels.postal_code = hotel_sales.sales_id
        join
    postal_code_location ON hotels.district = postal_code_location.district 

UNION SELECT 

    malls.postal_code AS ' Mall Postal Code',
    name AS 'Mall Name',
    latitude AS 'Latitude',
    longitude AS 'Longitude',
    address AS 'Mall Address',
    hyperlink AS 'Mall Hyperlink',
    malls.district AS 'Mall District',
    'mall' AS type
FROM
malls

        join
    hotel_sales ON malls.postal_code = hotel_sales.sales_id
        join
    postal_code_location ON hotels.district = postal_code_location.district

这个错误是关于

在您的查询中消除列column column_id的歧义

它应该是这样的

SELECT
    hotels.postal_code AS ' Hotel Postal Code',
    hotels.name AS 'Hotel Name',
    hotels.latitude AS 'Latitude',
....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM