【问题标题】:SQL Command not properly ended OracleSQL 命令未正确结束 Oracle
【发布时间】:2013-01-05 20:27:20
【问题描述】:

下面的我的 SQL 查询说它在第一个 Inner Join 时没有正确结束?如果我删除第二个表和 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

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

【问题讨论】:

标签: sql oracle


【解决方案1】:

您的 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

WHERE 子句出现在JOIN 之后和GROUP BY 之前。此外,您应该使用一种类型的连接语法。您同时使用了显式和隐式语法。我将homesbooking 的连接移动到JOIN,而不是在表格之间使用逗号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-15
    • 2022-01-18
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    相关资源
    最近更新 更多