为什么我在此查询中为From子句中的表获取了无效的标识符?

时间:2017-10-20 21:12:26

标签: sql oracle oracle11g

我在下面有这个查询:

Select b.b_id as Business_id, b.business_name, Average_Rating, b.review_count AS Review_count
FROM (
    SELECT b.b_id AS Business_id, AVG(r.rating) AS Average_Rating
    FROM Business b
    JOIN Business_Category bc ON b.bc_id = bc.bc_id
    JOIN Review r ON b.b_id = r.b_id
    WHERE bc.category_name = 'Breakfast and Brunch' AND b.city = 'San Jose' AND b.state = 'CA'
    GROUP BY b.b_id
) t_one
INNER JOIN Business b_one ON t_one.b_id = b_one.b_id
ORDER BY Average_Rating DESC, Review_count DESC, Business_Id ASC;

我正在invalid identifier进入INNER JOIN Business b_one ON t_one.b_id = b_one.b_id t_one

错误:

  

ORA-00904:“T_ONE”。“B_ID”:标识符无效

1 个答案:

答案 0 :(得分:1)

您的别名b不在外部查询的范围内。

SELECT b_one.b_id as Business_id, b_one.business_name, Average_Rating, b_one.review_count AS Review_count
FROM (
    SELECT b.b_id AS Business_id, AVG(r.rating) AS Average_Rating
    FROM Business b
    JOIN Business_Category bc ON b.bc_id = bc.bc_id
    JOIN Review r ON b.b_id = r.b_id
    WHERE bc.category_name = 'Breakfast and Brunch' AND b.city = 'San Jose' AND b.state = 'CA'
    GROUP BY b.b_id
) t_one
INNER JOIN Business b_one ON t_one.b_id = b_one.b_id
ORDER BY Average_Rating DESC, Review_count DESC, Business_Id ASC;