如何使用带有字段的计数函数查询每个部门的员工人数,Dept_id
使用下面的数据结构?Dept_name
Number of employees
create database Emp_det
create table Dept
(
Dept_ID int not null primary key,
Dept_name varchar(255)
)
create table Emp_table
(
Emp_no int not null primary key,
Emp_name varchar(255) not null,
Dept_ID int foreign key references Dept(Dept_ID),
Emp_status varchar(255)
)
create table Salary_table
(
Emp_no int not null foreign key references Emp_table(Emp_no),
From_date datetime,
End_date datetime,
Basic int,
HRA int,
Others int,
Total int,
Emp_status varchar(255),
constraint pk_emp_det primary key (emp_no,From_date)
);
insert into Dept
values(10, 'I.T'), (11, 'H.R'),(12, 'Procurement'),(13, 'QS');
insert into Emp_table
values(1111,'Manivannan','10','A'),
(1222,'Faizal','10','A'),
(4122,'Marzook','10','A'),
(1223,'Venu','11','A');
insert into Salary_table
values(1111,'01/09/2012','1/10/2012',10000,10000,2000,22000,'A'),
(1222,'01/09/2012','1/10/2012',5000,5000,1000,11000,'A'),
(4122,'01/09/2012','1/10/2012',1000,1000,5000,2500,'A'),
(1223,'01/09/2012','1/10/2012',10000,10000,2000,22000,'A')