我下面的SQL查询说它在第一次内部连接上没有正确结束?如果我删除了第二个表和where子句,查询就可以了吗?
SELECT homes.home_id, homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft,
listagg(features.feature_name, '\n') WITHIN GROUP(ORDER BY features.feature_name) features, home_type.type_name
FROM homes, bookings
WHERE bookings.booking_end < date '2013-01-23' OR bookings.booking_start > date '2013-01-22' AND bookings.home_id <> homes.home_id
INNER JOIN home_feature ON homes.home_id = home_feature.home_id
INNER JOIN home_type ON home_type.type_code = homes.type_code
INNER JOIN features ON home_feature.feature_id = features.feature_id
GROUP BY homes.home_id, homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft, home_type.type_name
Run Code Online (Sandbox Code Playgroud)
任何人都可以看到我的查询有任何明显错误吗?
您的WHERE子句位于错误的位置,并且您正在混合连接类型:
SELECT homes.home_id,
homes.title, homes.description,
homes.living_room_count,
homes.bedroom_count,
homes.bathroom_count,
homes.price,
homes.sqft,
listagg(features.feature_name, '\n') WITHIN GROUP(ORDER BY features.feature_name) features,
home_type.type_name
FROM homes
INNER JOIN bookings
ON bookings.home_id = homes.home_id
INNER JOIN home_feature
ON homes.home_id = home_feature.home_id
INNER JOIN home_type
ON home_type.type_code = homes.type_code
INNER JOIN features
ON home_feature.feature_id = features.feature_id
WHERE bookings.booking_end < date '2013-01-23'
OR booking_start > date '2013-01-22'
GROUP BY homes.home_id, homes.title, homes.description,
homes.living_room_count, homes.bedroom_count,
homes.bathroom_count, homes.price, homes.sqft, home_type.type_name
Run Code Online (Sandbox Code Playgroud)
该WHERE条款出现在JOIN之前和之后GROUP BY.您还应该使用一种类型的连接语法.您使用的是显式和隐式语法.我移动的加盟homes,并booking为JOIN使用该表之间的逗号而不是.