当前位置:网站首页>TYUT太原理工大学2022数据库之关系代数小题
TYUT太原理工大学2022数据库之关系代数小题
2022-07-06 09:19:00 【啦啦噜噜^_^】
这种题有两种出题模式:
第一种是给出你含有数字、字母或者属性的几组表格,让你用关系代数运算
第二种是会给出“关系数据库模式”,让我们用“关系代数表达式”表示各种查询,相对第一种较难
今年随机出
让我们来浅看一下概念:
一、关系数据库模式:简记为R(A1,A2,~~~An),R为关系名,A为属性名
eg:公司(公司编号、公司名、地址)
eg:S (S#,SNAME,AGE,SEX)(有的关系模式会是纯英文)
二.关系代数表达式:
交n、并U、差-(高中学过,略)、笛卡尔积x、选择σ、投影Π、连接
笛卡尔积:
S: | T: | |||||
A | B | A | B | |||
3 | 4 | 1 | 5 | |||
7 | 2 | 3 | 6 |
则SxT=
| S.A | S.B | T.A | T.B |
| 3 | 4 | 1 | 5 |
| 3 | 4 | 3 | 6 |
| 7 | 2 | 1 | 5 |
| 7 | 2 | 3 | 6 |
笛卡尔积是水平方向的运算,第一个表的每行分别与第二个表的每行相连
选择σ:
语法:σ+条件(所查询的表)
eg:商品(商品ID,商品名称,价格,品牌,型号,颜色,生产商,产地)
查询产地是上海的商品信息:σ产地=‘上海’ (商品)
选择是水平方向的查询,其结果是符合条件的商品的所有属性(字符串记得加单引号)
投影Π:
eg:商品(商品ID,商品名称,价格,品牌,型号,颜色,生产商,产地)
查询产地是上海的商品ID,商品名称:Π商品ID,商品名称(σ产地=‘上海’(商品))
投影是竖直方向的查询,其结果是单个属性
连接:
连接一般用于表格,连接有自然连接、外连接、左连接、右连接。老师不会为难咱们,题库中也只有自然连接题,所以只讲最简单的自然连接


如上所示,连接就是把两个关系中具有相同的属性的行进行笛卡尔运算
除:


上题中R作为被除数,S作为除数
方法:(1)先找出R、S中的共有属性B、C
(2)再找出被除数R中共有属性值与S中共有属性值相同的行,
即R(2):
| A | B | C |
| a1 | b1 | c2 |
| a1 | b2 | c3 |
| a2 | b2 | c3 |
| a1 | b2 | c1 |
(3)去掉第二步表R(2)中的共有属性列B、C,只留A列
即
| A |
| a1 |
| a1 |
| a2 |
| a1 |
化简得
掌握这些基本概念,我们就可以做题啦,SQL的查询方式多样,所以很多题答案不唯一。
例1:真题
解:1.
例2、

解:


例3、

解:

边栏推荐
- 4.30动态内存分配笔记
- [algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
- 4.30 dynamic memory allocation notes
- 面试必备:聊聊分布式锁的多种实现!
- Iterable、Collection、List 的常见方法签名以及含义
- 记录:初次cmd启动MySQL拒接访问之解决
- Record: the solution of MySQL denial of access when CMD starts for the first time
- Record: I accidentally wrote a recursion next time
- 【RTKLIB 2.4.3 b34 】版本更新简介一
- Itext 7 生成PDF总结
猜你喜欢

十分鐘徹底掌握緩存擊穿、緩存穿透、緩存雪崩

C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)

121 distributed interview questions and answers

How to ensure data consistency between MySQL and redis?
![[untitled]](/img/b1/9a2bebebb24132a405fc4e7d854e51.png)
[untitled]

继承和多态(上)

Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing

RTKLIB: demo5 b34f.1 vs b33

编辑距离(多源BFS)

面试必备:聊聊分布式锁的多种实现!
随机推荐
Experience summary of autumn recruitment of state-owned enterprises
[algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
染色法判定二分图
错误: 找不到符号
Role movement in the first person perspective
GPS高程拟合抗差中误差的求取代码实现
Record: solution of 404 error of servlet accessing database in dynamic web project
RTKLIB: demo5 b34f.1 vs b33
GNSS positioning accuracy index calculation
【RTKLIB 2.4.3 b34 】版本更新简介一
Error: sorting and subscript out of bounds
[untitled]
Devops' future: six trends in 2022 and beyond
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
面渣逆袭:Redis连环五十二问,三万字+八十图详解。
基本Dos命令
Containers and Devops: container based Devops delivery pipeline
Knowledge system of digital IT practitioners | software development methods -- agile
Redis介绍与使用
[GNSS data processing] Helmert variance component estimation analysis and code implementation