我不太清楚为什么,但我的代码似乎不起作用。要么我得到错误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

关于mysql - MySQL错误1054:“on子句”中的未知列“hotels.postal_code”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21681482/

10-10 20:47