
where a.工号=c.工号
and c.编号=b.编号
and b.名称 in ('体 *** 队','篮球队')
2. select distinct a.工号, a.姓名, a.年龄 from 职工 a
where a.性别='男' and exists
(select 1 from 参加 b where b.工号=a.工号)
3. select a.工号 from 职工 a
where a.工号 in
(select b.工号 from 参加 b group by b.工号 having count(*) >2)
4. select a.* from 职工 a
where not exists ( select * from 社团 b where not exists
(select * from 参加 c where c.工号=a.工号 and c.编号=b.编号)
)
1,社会团体(编号,名称,负责人,活动地点) society参加(职工号,编号,参加日期)Join
职工(职工号) Employee
select 职工号
from Employee a
where a.职工号 in(select 职工号 from Join
where 编号 in(select 编号 from Join
where 职工号='1001'))
2,select (select 名称 from society where 编号=Join.编号) 社会团体名称,
sum(职工编号) 参加人数
from Join where 编号 =
(select bb.编号 from (select 编号,count(*) 数量 from Join group by 编号 ) bb
where bb.数量 =( select max(数量) from --得到最大数量
(select 编号,count(*) 数量 from Join
group by 编号 ) aa ) )--根据最大数量得到团体编号
3,grant select, insert, delete on society to 李平 with grant option
grant select, insert, delete on Join to 李平 with grant option
create table 职工表(
职工号 varchar(15) not null,
姓名 varchar(10) not null,
年龄 int,
性别 char(2)
primary key(职工号))
create table 社会团体
(
编号 varchar(15) not null,
名称 varchar(10) not null,
负责人 varchar(15) not null,
活动地点 varchar(30)
primary key(编号)
foreign key(负责人) references 职工表(职工号)
)
create table 参加
(
职工号 varchar(15) not null,
编号 varchar(15) not null,
参加日期 datetime,
primary key(职工号,编号),
foreign key(职工号) references 职工表(职工号),
foreign key(编号) references 社会团体(编号)
)
create view 社会负责人 as
select a.编号 as 编号,a.名称 as 名称,a.负责人 as 负责人职工号,b.姓名 as 负责人姓名,b.性别 as 负责人性别
from 社会团体 a,职工表 b
where a.负责人=b.职工号
create view 参加人情况 as
select a.职工号 as 职工号,a.姓名 as 姓名,b.编号 as 社团编号,c.名称 as 社团名称,b.参加日期 as 参加日期
from 职工表 a,参加 b,社会团体 c
where a.职工号=b.职工号
andc.编号=b.编号
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)