在一个 Select 语句中使用计数函数和计数总数的百分比

Using Count Function and Percentage of Count Total in One Select Statement

我有三个数据 tables 员工、部门和位置。 我想显示每个州的员工总数以及每个州的员工百分比。 Employees table 和 Departments table 有一个相同的列 Department_ID,Departments table 和 Locations table 有一个相同的列 [=18] =].这是我为代码编写的内容:

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;

但是,当我 运行 代码时,错误 "from keyword not found where expected" 出现了。我该如何解决?

你需要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;