create table 部门表
( 部门表 char(2) nut null primary key,
部门名称 varchar(30) not null
)
create table 雇员表
( 雇员代号 char(4) not null primary key,
雇员姓名 varchar(20) not null
)
create table 任职表
( 雇员代号 char(4) not null,
部门号 char(2) not null,
开始时间 datetime not null,
备注 varchar(1000) null,
constraint pk_works primary key(雇员代号,部门号,开始时间),
constraint fk_employees foreign key(雇员代号)
referenses 雇员表(雇员代号)on delete cascade
constraint fk_employees foreign key(部门号)
references 部门表(部门号) )
如何获得每个部门都工作过的雇员名单 最好能解释一下 语言的逻辑意义
create table 部门表
( 部门表 char(2) nut null primary key,
部门名称 varchar(30) not null
)
create table 雇员表
( 雇员代号 char(4) not null primary key,
雇员姓名 varchar(20) not null
)
create table 任职表
( 雇员代号 char(4) not null,
部门号 char(2) not null,
开始时间 datetime not null,
备注 varchar(1000) null,
constraint pk_works primary key(雇员代号,部门号,开始时间),
constraint fk_employees foreign key(雇员代号)
referenses 雇员表(雇员代号)on delete cascade
constraint fk_employees foreign key(部门号)
references 部门表(部门号) )
如何获得每个部门都工作过的雇员名单 最好能解释一下 语言的逻辑意义 slect 雇员姓名 from 雇员表 as a where
not exists (select b.部门号 from 部门表 as b where b.部门号 not in
( select c.部门号 from 任职表 as c
where a.雇员代号=c.雇员代号
)
)
这样行不行
( 部门表 char(2) nut null primary key,
部门名称 varchar(30) not null
)
create table 雇员表
( 雇员代号 char(4) not null primary key,
雇员姓名 varchar(20) not null
)
create table 任职表
( 雇员代号 char(4) not null,
部门号 char(2) not null,
开始时间 datetime not null,
备注 varchar(1000) null,
constraint pk_works primary key(雇员代号,部门号,开始时间),
constraint fk_employees foreign key(雇员代号)
referenses 雇员表(雇员代号)on delete cascade
constraint fk_employees foreign key(部门号)
references 部门表(部门号) )
如何获得每个部门都工作过的雇员名单 最好能解释一下 语言的逻辑意义
create table 部门表
( 部门表 char(2) nut null primary key,
部门名称 varchar(30) not null
)
create table 雇员表
( 雇员代号 char(4) not null primary key,
雇员姓名 varchar(20) not null
)
create table 任职表
( 雇员代号 char(4) not null,
部门号 char(2) not null,
开始时间 datetime not null,
备注 varchar(1000) null,
constraint pk_works primary key(雇员代号,部门号,开始时间),
constraint fk_employees foreign key(雇员代号)
referenses 雇员表(雇员代号)on delete cascade
constraint fk_employees foreign key(部门号)
references 部门表(部门号) )
如何获得每个部门都工作过的雇员名单 最好能解释一下 语言的逻辑意义 slect 雇员姓名 from 雇员表 as a where
not exists (select b.部门号 from 部门表 as b where b.部门号 not in
( select c.部门号 from 任职表 as c
where a.雇员代号=c.雇员代号
)
)
这样行不行
select 雇员代号,count(1) as Counts from (select distinct 雇员代号,部门号 from 任职表) a
where counts=(select count(1) from 部门表)
group by 雇员代号
insert into 部门表
select '01','办公室' union all
select '02','接待办' union all
select '03','打字室' insert into 雇员表
select 'A1','张三' union all
select 'A2','李四' union all
select 'A3','王五' insert into 任职表
select 'A1','01','2008-1-1','' union all
select 'A1','02','2008-2-2','' union all
select 'A1','03','2008-3-3','' union all
select 'A2','01','2008-1-1',''select * from
[雇员表] where [雇员代号] in
(
select [雇员代号] from
(
select distinct [雇员代号],[部门号]
from [任职表]
) a
group by [雇员代号]
having COUNT(*)=(select COUNT(*) from [部门表])
)
雇员代号 雇员姓名
A1 张三
group by 雇员代号
having count(1)=(select count(1) from 部门表)
select a.雇员姓名 from 雇员表 a
,(select 雇员代码 from 任职表
group by 雇员代码 having count(*)=select(count(*)) from 部门表) b
where a.雇员代码=b.雇员代码
--部门表
insert into department
select '01','办公室' union all
select '02','接待办' union all
select '03','打字室'
--雇员表
insert into Employee
select 'A1','张三' union all
select 'A2','李四' union all
select 'A3','王五'
--任职表
insert into job
select 'A1','01','2008-1-1','' union all
select 'A1','02','2008-2-2','' union all
select 'A1','03','2008-3-3','' union all
select 'A2','01','2008-1-1',''select select dd.department,EE.UserName from department dd join job jj on dd.departID=jj.departID join
Employee on EE.EID=JJ.EID