我不太清楚为什么,但我的代码似乎无法工作。它或者我得到错误1052或1054. 这是我的代码。请帮忙。MySQL错误1054:'on子句'中的未知列'hotels.postal_code'
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
你可以分享你的表中的DDL? – Mureinik
'ON hotels.postal_code = hotel_sales.sales_id'似乎是错误的。听起来对我来说应该是'ON hotels.hotel_id = hotel_sales.hotel_id'? –
在您的第二个选择中,您加入了'hotels.postal_code',但该查询中没有使用“酒店”。你正在从'商场'选择。 –