2013-01-22 43 views
3

我的SQL查询如下所示,它没有在第一个Inner Join上正确结束?如果我删除了第二个表和where子句,查询仍然正常?SQL命令未正确结束Oracle

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 

任何人都可以看到我的查询有任何明显的错误吗?

+0

建立你的模式。 –

+0

做**不**混合隐式连接和显式连接语法。另外'JOIN'关键字在* WHERE子句之前。手册中的更多详细信息:http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2065646 –

+0

你不能在那里放一个'where' – Xophmeister

回答

6

WHERE条款是在错误的地方,你是混合连接类型:在JOINGROUP BY

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 

WHERE子句出现。你也应该使用一种类型的连接语法。您正在使用显式和隐式语法。我将homesbooking的连接移至JOIN,而不是在表之间使用逗号。

+0

哦,我明白了,谢谢你您的帮助 – user1851487

+0

@ user1851487欢迎您,很高兴为您提供帮助。 :) – Taryn

相关问题