如何解析Oracle DB查询结果中的无效标识符?

时间:2016-02-18 07:48:29

标签: sql oracle

我是Oracle DB的新手,我需要列出region表中每个区域的部门数量。

这是我的SQL语句:

SELECT r.region_id, COUNT(d.department_id) "Number of Department"
FROM region r, department d
WHERE r.region_id = d.region_id
GROUP BY r.region_id

我收到以下错误:

  

" D"," region_id":无效的标识符

我该如何纠正?

编辑1 -

这是从部门到地区的表格

部门表
Dept_id,Dept_name,Manager_Id,Location_Id

地点表
Location_id,street_add,postal_code,city,state_province,country_id

国家表
Country_Id,Country_name,Region_Id

地区表
Region_Id,Region_Name

1 个答案:

答案 0 :(得分:0)

你需要将所有四个表连接在一起,从这个角度来看,这对我来说是直截了当的。这些方面应该有用:

SELECT r.region_id, COUNT(d.department_id) "Number of Department"
FROM department d INNER JOIN location l
    ON d.location_id = l.location_id
INNER JOIN country c
    ON l.country_id = c.country_id
INNER JOIN region r
    ON c.region_id = r.region_id
GROUP BY r.region_id