数据库求助!!!
考虑以下关系模式:eployee(empno,name,office,age)books(isbn,title,authors,publisher)loan(empno,...
考虑以下关系模式:
eployee(empno,name,office,age)
books(isbn,title,authors,publisher)
loan(empno,isbn,date)
用关系代数写出下列查询:
a、找出借了任何由McGraw-Hill出版的书的员工的姓名。
b、找出借了由McGraw-Hill出版的所有的书的员工的姓名。
c、找出借了至少5本不同的由McGraw-Hill出版的书的员工的姓名
d、对每个出版商,找出借了至少5本该出版商的书的员工的姓名。
要数理逻辑表达方式的~ 展开
eployee(empno,name,office,age)
books(isbn,title,authors,publisher)
loan(empno,isbn,date)
用关系代数写出下列查询:
a、找出借了任何由McGraw-Hill出版的书的员工的姓名。
b、找出借了由McGraw-Hill出版的所有的书的员工的姓名。
c、找出借了至少5本不同的由McGraw-Hill出版的书的员工的姓名
d、对每个出版商,找出借了至少5本该出版商的书的员工的姓名。
要数理逻辑表达方式的~ 展开
2个回答
展开全部
a、简单得很,多表自然连接
select distinct e.name from eployee E, books B, loan L
where L.isbn = B.isbn
and L.empno = E.empno
and B.publisher = "McGraw-Hill"
b、思路:有那么些人,不存在McGraw-Hill出版的书而他们没有借
select name from employee E
where not exists( select 1 from loan L
where L.empno = E.empno
and not exists( select 1 from books B
where B.isbn = L.isbn
and B.publisher = "McGraw-Hill" ) )
c、技巧:返回单值的子查询可用于逻辑判断;不同的书——distinct isbn
select name from employee E
where exists( select 1 from loan L
where L.empno = E.empno
and ( select count( distinct isbn ) from books B
where B.isbn = L.isbn
and B.publisher = "McGraw-Hill" ) >= 5 )
d、
select E.name from employee E
where exists( select 1 from loan L
where E.empno = L.empno
and ( select count(*) from books B
where B2.isbn = L.isbn
and publisher = L.publisher ) >= 5 )
select distinct e.name from eployee E, books B, loan L
where L.isbn = B.isbn
and L.empno = E.empno
and B.publisher = "McGraw-Hill"
b、思路:有那么些人,不存在McGraw-Hill出版的书而他们没有借
select name from employee E
where not exists( select 1 from loan L
where L.empno = E.empno
and not exists( select 1 from books B
where B.isbn = L.isbn
and B.publisher = "McGraw-Hill" ) )
c、技巧:返回单值的子查询可用于逻辑判断;不同的书——distinct isbn
select name from employee E
where exists( select 1 from loan L
where L.empno = E.empno
and ( select count( distinct isbn ) from books B
where B.isbn = L.isbn
and B.publisher = "McGraw-Hill" ) >= 5 )
d、
select E.name from employee E
where exists( select 1 from loan L
where E.empno = L.empno
and ( select count(*) from books B
where B2.isbn = L.isbn
and publisher = L.publisher ) >= 5 )
更多追问追答
追问
先谢谢你啊~不过我是想要π (σ())这种的...还有就是最后两个不会...能不能麻烦告诉我下?
追答
抱歉,其实我写到第三个查询命令时,已经发现你要的是数理逻辑表达方式,而不是SQL命令,无奈那些东西都忘得差不多了,真回答不好,但又觉得或许SQL命令也会给你些启发,于是就码上去了。另外,这几个查询命令也是未加试验的,正想搭建个环境试试呢。
苏州神码物信智能科技
2024-08-22 广告
2024-08-22 广告
在苏州神码物信智能科技有限公司,我们协助客户高效处理海关信息查询需求。通过我们专业的系统对接与数据分析服务,能够迅速获取最新的海关进出口信息、货物清关状态及关税政策变动等关键数据,确保供应链透明高效。我们致力于为客户提供定制化解决方案,助力...
点击进入详情页
本回答由苏州神码物信智能科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询