这里是带有值的
SQL FIDDLE 和下表模式。
我想选择id_emp,fname_emp,TotalProject
一个条件,其skillsid
in (1,2)
。我试过的查询给出了错误的输出。
create table employee_emp(
id_emp int identity(1,1),fname_emp varchar(20),lname_emp varchar(20))
insert into employee_emp values('John','Cena');
insert into employee_emp values('Michel','shawn');
insert into employee_emp values('Jay','mac');
insert into employee_emp values('David','jackson');
create table skills_skl(
idemp_skl int,idskill_skl int
)
insert into skills_skl values(1,1);
insert into skills_skl values(1,2);
insert into skills_skl values(1,3);
insert into skills_skl values(1,4);
insert into skills_skl values(2,2);
insert into skills_skl values(2,3);
insert into skills_skl values(3,1);
insert into skills_skl values(3,4);
insert into skills_skl values(4,2);
create table employee_ejp(
id_ejp int identity(1,1),idemp_ejp int ,idproject_ejp int)
insert into employee_ejp values(1,1);
insert into employee_ejp values(1,2);
insert into employee_ejp values(1,3);
insert into employee_ejp values(2,3);
insert into employee_ejp values(2,2);
insert into employee_ejp values(3,1);
insert into employee_ejp values(4,4);
我试过的查询
1)
select a.id_emp,a.fname_emp,count(b.id_ejp) TotalP from employee_emp a
join employee_ejp b on a.id_emp=b.idemp_ejp
group by a.id_emp,a.fname_emp
2)
select a.id_emp,a.fname_emp,count(b.id_ejp) TotalP from employee_emp a
join employee_ejp b on a.id_emp=b.idemp_ejp join skills_skl c on c.idskill_skl=a.id_emp
where c.idskill_skl in (1,2)
group by a.id_emp,a.fname_emp