我在下面有一个EMPLOYEE
表:
EMP_ID DEPT_ID
101 1
102 2
103 3
104 1
和DEPARTMENT
表格如下:
DEPT_ID COUNTS
1
2
3
我想编写一个查询,该查询将计算属于某个部门的Employee
的数量并将其存储到Department
列表中,以便Department
表看起来像:
DEPT_ID COUNTS
1 2
2 1
3 1
我试过了:
update department p
set p.counts = (select count(*) from EMPLOYEE e where p.dept_id = e.dept_id
group by e.dept_id)
但它不起作用。
答案 0 :(得分:2)
删除group by
和第一个别名:
update department p
set counts = (select count(*) from EMPLOYEE e where p.dept_id = e.dept_id);