
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
select 职工号,姓名from 职工
where 职工号 in (select 职工号
from 参加
where 编号 in (select 编号
from 社会团体
where 名称='唱歌'))
select 名称
from 社会团体
where 编号 in (select 编号
from 参加
where 职工号='1001')
select count(名称) as 参加人数 ,名称 from 社会团体,参加 where 社会团体.编号=参加.编号 group by 名称
create view shitu as
select 职工.职工号,姓名,社会团体.编号,名称,参加日期
from 职工,社会团体,参加 where 职工.职工号=参加.职工号 and 社会团体.编号=参加.编号 order by 职工.职工号
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)