2013-01-22 159 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

相關問題