1

我不太清楚为什么,但我的代码似乎无法正常工作。我得到错误 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
4

2 回答 2

2

代替

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
于 2014-02-10T15:48:05.927 回答
1

这个错误是关于

消除查询中的 column_id 歧义

它应该是这样的

SELECT
    hotels.postal_code AS ' Hotel Postal Code',
    hotels.name AS 'Hotel Name',
    hotels.latitude AS 'Latitude',
....
于 2014-02-10T15:48:50.220 回答