簡體   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