数据库关系代数作业(1)-CAP表

更新时间:2023-07-25 20:59:07 阅读: 评论:0

数据库关系代数作业(1)-CAP表以CAP表作为练习的对象,顾客customers,代理商agents,和商品products,订单表orders为例⼦
fprintfGet the names of customers who order at least one product priced at $0.50.
1.查询所有订购了⾄少⼀个价值为0.5的商品的客户名字
答案在2.7.8
CHEAPS:=(PRODUCTS where price =0.50)[pid]小学英语三年级上册
((ORDERS⋈CHEAPS )⋈CUSTOMERS)[cname]
或者合并⼀步
((DROERS⋈(PRODUCTS WHERE price=0.50)[pid]) ⋈CUSTOMERS)[cname] 2. Find cids of all customers who don’t place any order through agent a03取出全部没有通过代理商a03订购商品的顾客的cid值。
答案:例⼦2.9.2
(ORDERS where aid=’a03’)[cid]
摩登家庭下载然后
ORDERS[cid]-(ORDERS where aid=’a03’)[cid]
或者
CUSTOMERS[cid]-(ORDERS where aid=’a03’)[cid].
来表⽰
3. Retrieve customers who place orders only through agent a03.
检索仅通过代理商a03订购商品的客户
例:2.9.3
ORDERS[cid]-(ORDERS where aid <>’a03’)[cid]
4. Find products that have never been ordered by a customer bad in New York through an agent bad in Boston.找出没有被任何⼀个在New York的顾客通过下Boston的代理商订购的所有商品
例2.9.4:
PRODUCTS[pid]-(((CUSTOMER where city=‘New York‘)[cid]⋈ORDERS) ⋈AGENTS where city=’Boston’)[pid] 5. Get names of customers who order all products priced at $0.50.
获取订购价格为0.50的商品的顾客的名字
例:2.9.5
superheroes
“谁订购了所有的商品”可以考虑⽤除运算来得到顾客的cid值:
D[cid,pid] ÷(P where price=0.50)[pid]
要得到名字还要把结果和表CUSTOMERS做连接投影到Cname
sobering((ORDERS[cid,pid] ÷(P  where prices=0.50)[pid]) ⋈CUSTOMERS)[cname]
6. Get cids of customers who order all products that anybody orders.
获取订购了所有被任何⼈订购过⼀次的商品的顾户的 cid值北京 韩语
答案例2.9.6
所有“商品”的列表,需要从ORDERS表⽽不是PRODUCTS表投影⽽来
ORDERS[cid,pid] ÷ORDERS[pid]
7. Get aids of agents who take orders on at least that t of products ordered by c004.
取出所有接到⾄少顾客C004订购的商品集合(可能会更多)的订单的代理商的aid值。
例2.9.7 取出接到所有c004订购的商品的订单的代理的aid值
ORDERS[aid,pid] ÷(ORDERS where cid=’c004’)[pid]
8 Get cids of customers who order both products p01 and p07.
查询订购了P01和P07这两种商品的顾客的cid值
例⼦:2.9.8
错误答案:OEDERS where pid=’p01’and pid=’p07’
正确答案:(Orders where pid=’p01’)[cid]∩( Order where  pid=’p07’)[cid]
9 Get cids of customers who place an order through at least one agent who places an order for product p03.
取出从⾄少⼀个接受订购商品p03订单的代理商订购的顾客的cid值。
答案:例2.9.9
spotlight是什么意思X:=ORDERS
吸血鬼日记第3季(X⋈(ORDERS where pid=’p03’)[aid])[cid]
10. Get cids of all customers who have the same discount as any customer in Dallas or Boston.
获取与达拉斯或波⼠顿任何客户享有相同折扣的所有客户的CID
答案2.9.10
D:=CUSTOMERS
((CUSTOMERS where city=’Dallars’ or city=’Boston’)[discnt]⋈ Orders)[cid]
11. Get pids of products not ordered by any customer living in a city who name begin with the letter D.
查询没有被⽣活在以字母D开头的城市的顾客订购的商品的pid值
entrance答案:2.9.12
C where city>=’D’and city<’E’
P[pid]-(ORDERS⋈(CUSTOMERS where city>=’O’and city=’E’))[pid]
12. List pids of products that are ordered through agents who place orders for (possibly different) customers who order at least one product from an agent who has placed an order for customer c001.
列出通过符合下列条件的代理商订购的商品的pid列表。这些代理商从可能不同的顾客处接受订单,⽽这些顾客从⼀个接收过顾客c001订单的代理商处订购了⾄少⼀个商品。
答案 例2.9.11
kokia白雪X,Y,Z:=ORDERS
(Z⋈(Y⋈(X⋈(ORDERS where cid='c001')[aid])[cid])[aid])[pid]

本文发布于:2023-07-25 20:59:07,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/188626.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:商品   订购   代理商   订单   客户   练习
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图