SQL 命令未正确结束 Oracle
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14461418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Command not properly ended Oracle
提问by user1851487
My SQL query below says that it is not ended properly on the first Inner Join?If i remove the second table and the where clause the query is fine though?
我下面的 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
Can anybody see any obvious errors with my query?
任何人都可以看到我的查询有任何明显的错误吗?
回答by Taryn
Your WHERE
clause is in the wrong place and you are mixing join types:
您的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
The WHERE
clause appears after the JOIN
and before GROUP BY
. Also you should use one type of of join syntax. You were using both explicit and implicit syntax. I moved the join of homes
and booking
to a JOIN
instead of using a comma between the tables.
该WHERE
子句出现在 之后JOIN
和之前GROUP BY
。您还应该使用一种类型的连接语法。您使用了显式和隐式语法。我移动的加盟homes
,并booking
为JOIN
使用该表之间的逗号而不是。