我在下面有这个查询:
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”:标识符无效
答案 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;