我有三个数据表Employees,Departments和Locations。 我想显示每个州的员工总数以及每个州的员工百分比。 Employees表和Departments表有一个名为Department_ID的相同列,Departments表和Locations表有一个名为Location_ID的相同列。这是我为代码编写的内容:
select l.state_province e.count(*) as "Employees in State",
e.count(*)*100/sum(e.count(*)) over ()
from employees e
full outer join departments d on e.department_id = d.department_id
full outer join locations l on l.location_id = d.location_id
order by l.state_province;
然而,错误"来自关键字未找到预期的"在我运行代码时出现。我该如何解决?
答案 0 :(得分:1)
您需要group by
。常规联接应该没问题:
select l.state_province, count(*) as "Employees in State",
count(*) * 100/sum(count(*)) over ()
from employees e join
departments d
on e.department_id = d.department_id join
locations l
on l.location_id = d.location_id
group by l.state_province
order by l.state_province;