吉林大学数据库系统概念SQL、关系代数习题汇总

news/2025/2/23 15:08:50

吉林大学数据库系统概念SQL、关系代数习题汇总(持续更新)

奔腾 数据库系统原理考试(A卷)

在这里插入图片描述

// (1)
create table branch(
branch_name varchar(20),
branch_city varchar(20),
assets numeric(12, 2),
primary key (branch_name));

create table customer(
customer_name varchar(20),
customer_street varchar(20),
customer_city varchar(20),
primary key (customer_name));

create table loan(
loan_number varchar(5),
branch_name varchar(20),
amount numeric(12, 2),
primary key (loan_number),
foreign key (branch_name));

create table borrower(
customer_name varchar(20),
loan_number varchar(5),
primary key (customer_name, loan_number));

create table account(
account_name varchar(20),
branch_name varchar(20),
balance numeric(12, 2),
primary key (account_name),
foreign key (branch_name));

create table depositor(
customer_name varchar(20),
account_name varchar(20),
primary key (customer_name, account_name));

// (2)关系代数
Π Pi Πcustomer_name,account_number,balance( σ sigma σbranch_name=‘Brighton’(account Join depositor))

// (2) sql
select customer_name, account_number, balance 
from account natural join depositor 
where account.branch_name = 'Brighton'

// (3)关系代数
σ sigma σavg_balace<5000(branch_name G mathcal{G} G avg(balance) as avg_balance (account))
// 或者 标准答案写法
σ sigma σavg_balance<5000 ( ρ ho ρ branch_balance(branch_name,avg_balance)(branch_name G mathcal{G} G avg(balance)(account)))

// (3) sq1
select branch_name, avg(balance) 
from account 
group by branch_name 
having avg(balance) < 5000

// (4)关系代数
Π Pi Π customer_name (borrower) - Π Pi Π customer_name (despositor)

// (4) sq1
select distinct customer_name from borrower
where customer_name not in (
select distinct customer_name from depositor)

// (5) 关系代数
account ← leftarrow ← Π Pi Π account_number,branch_name,balance*1.03 ( σ sigma σ balance>avg(balance) (account)) igcup Π Pi Π account_number,branch_name,balance ( σ sigma σ balance<=avg(balance) (account))

// (5) sq1
update from account set balance = 
case
	when balance > avg(balance) then balance * 1.03
end
// 标准答案
update from account set balance = balance * 1.03 
where balance > 
(select avg(balance) from account)

奔腾 2018.6.15

在这里插入图片描述

// 关系代数 (1)
Π Pi Π Gname ( σ sigma σ Pname=‘wxy’ (GAME Join PERSON Join PG))

// (1) sql
select Gname from GAME 
natural join PG 
natural join PERSON 
where Pname = 'wxy'

// 关系代数 (2)
Π Pi ΠGname(GAME Join σ sigma σcnt>500 ( ρ ho ρGid_cnt(Gid,cnt)(Gid G mathcal{G} G count(Pid)(PG))))

// (2) sql
select Gname from GAME 
natural join PG 
group by Gid 
having count(Pid) > 500

// 关系代数 (3)
Π Pi Π Pname (PERSON Join ( Π Pi Π Pid ( σ sigma σ Gid=‘G01’(PG) - σ sigma σ Gid=‘G02’(PG))))

// (3) sql
select Pname from PERSON 
where Pid in 
(select Pid from PG where Gid = 'G01') 
and Pid not in 
(select Pid from PG where Gid = 'G02')

// 关系代数 (4)
Π Pi Π Gid,Pid(PG) ÷ div ÷ Π Pi Π Gid ( σ sigma σ type=‘益智类’(GAME))

// (5) sql
select distinct Gname from GAME
natural join PG
natural join PERSON
where PERSON.age between 15 and 25


// (6) sql
insert into PG (Pid, Gid)
values (P01, G02)


// (7) sql 做更新操作 假设新版本是2,GID = G01
update from GAME set version = 2
where Gid = 'G01'

奔腾 2016级

在这里插入图片描述

在这里插入图片描述

// (1)
create table books_rank (
BRID NUMBER(6),
BID CHAR(4),
BNAME VARCHAR(30) NOT NULL,
QTY_NO NUMBER(6)  NOT NULL,
QTY NUMBER(6,2) NOT NULL,
BUY_DATE DATE NOT NULL,
AVG_SCORE NUMBER(3,2),
PRIMARY KEY (BRID),
FOREIGN KEY (BID) REFERENCES books
); 


// (2)
 select distinct CID from orders where QTY between 1000 and 2000


// (3) 这个只能保证没买东西的顾客的购买金额为0
select c.CID, o.DOLLARS from customers as c 
left join orders as o 
on c.CID = o.CID 
// 如果要考虑一个顾客拥有多个订单,可以使用分组求和
select c.CID, sum(o.DOLLARS) as sumDollars 
from customers as c
left join orders as o
on c.CID = o.CID 
group by c.CID


// (4) 这个只能保证没买东西的顾客的购买金额为0
select max(salary) from orders
where orders < 
(select max(salary) from orders)


// (5) 权限的授予 grant <操作列表> on <关系> to <用户> 
grant insert, delete on book_ranks to Tom
// 如果只授予表中某几个属性的权限,可以这样写
grant insert(BNAME), delete on book_ranks to Tom
// 权限的收回 revoke <操作列表> on <关系> from <用户>
revoke insert on book_ranks from Tom

奔腾 2015级《数据库应用》期末考试试题

在这里插入图片描述
在这里插入图片描述

// (1)
create table users(
uid NUMBER(10) PRIMARY KEY,
uname CHAR(6) NOT NULL,
gender CHAR(1),
province VARCHAR2(10)
PRIMARY KEY (uid)
);


// (2) 这里不能distinct 因为有可能一个人对一个歌打分2次
select s.sname, l.score from users as u 
natural join listen_history as l
natural join songs as s
where uname = 'Smith' and YEAR(l.date_listen) = YEAR(NOW())
// 还有个问题是 数值为空时 要写成 0
// 一种方案是 但是貌似不能用 书上没写过这种
select s.sname, ifnull(l.score, 0) from users as u 
natural join listen_history as l
natural join songs as s
where uname = 'Smith' and YEAR(l.date_listen) = YEAR(NOW())
// 另外一种方案 case when 结构
select s.sname, l.score,
case 
	when l.score is null then 0
	else l.score
end
from users as u 
natural join listen_history as l
natural join songs as s
where uname = 'Smith' and YEAR(l.date_listen) = YEAR(NOW())


// (3)
select count(distinct u.uid) from users as u
natural join listen_history as l
natural join songs as s
where s.sname = 'XXX' and u.province = 'YYY'


// (4)
grant insert, delete on user_links to Tom


// (5)
select sid from songs order by avg_score desc

奔腾 2014级 《数据库应用》期末考试试题

在这里插入图片描述
在这里插入图片描述

// (1)这里没单独查名字是因为考虑到重名的客户没办法区分
select CID, CNAME from Customers where CNAME like 'A%'


// (2)
select * from Customers where ADDRESS is null order by CNAME desc


// (3)
select * from Sales where SALARY is not null and SALARY > 3000


// (4) 因为有多人重名,故使用all
select SID, SNAME from Sales 
where SALARY > all (
select SALARY from Sales
where SNAME = 'Smith')


// (5)
select CID from Orders where DATE_BUY 
between date(now())-interval 7 day and date(now())
group by CID
having count(*) >= 2


// (6)
select DOLLARS from Orders natural join 
(select PID, max(p1.QTY) from Products_rank as p1
where p1.QTY < (select max(p2.QTY) from Products_rank as p2))
// 或者
select DOLLARS from Orders natural join
(select PID, max(QTY) from 
(select PID, QTY from Products_rank
where QTY not in
(select max(QTY) from Products_rank)))

奔腾 2015级 《数据库原理》考试试题A

在这里插入图片描述

(1) 关系代数
Π Pi ΠMname,Maddress ( σ sigma σMRnum>=50(MD))

(2) 关系代数
Π Pi ΠMname,Maddress(MD Join σ sigma σMid<>256 (( Π Pi ΠMid,Pid(MP) ÷ div ÷ Π Pi ΠPid( σ sigma σMid=256(MD Join MP)))))

// (3)
select Pname, Mname from MD
natural join MP
natural join SP
where MP.Pnum < 10


// (4)
select MD.Mname, sum(MP.Pnum * SP.Price) as totalPrice
from MD natural join MP natural join SP
group by MD.Mid


// (5)
update from MP set Pnum = Pnum + 2000
where Pid in 
(select Pid from SP where Pname = '泉阳泉')
and Mid = 256

http://www.niftyadmin.cn/n/5863513.html

相关文章

基于Spring Boot的协同过滤电影推荐系统设计与实现(LW+源码+讲解)

专注于大学生项目实战开发,讲解,毕业答疑辅导&#xff0c;欢迎高校老师/同行前辈交流合作✌。 技术范围&#xff1a;SpringBoot、Vue、SSM、HLMT、小程序、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、安卓app、大数据、物联网、机器学习等设计与开发。 主要内容&#xff1a;…

万字长文解析:深入理解服务端渲染(SSR)架构与全栈实践指南

一、SSR核心原理深度剖析 1.1 技术定义与演进历程 服务端渲染&#xff08;Server-Side Rendering&#xff09;指在服务器端完成页面DOM构建的技术方案。其发展历程可分为三个阶段&#xff1a; 阶段时期典型技术传统SSR2000-2010JSP/PHP现代SSR2015-2020Next.js/Nuxt.js混合渲…

var、let、const区别

在 JavaScript 中&#xff0c;var、let 和 const 是用于声明变量的关键字&#xff0c;但它们的作用域、提升行为以及可变性等方面有显著区别。以下是它们的详细对比&#xff1a; 1. var 作用域: var 声明的变量是函数作用域&#xff08;function-scoped&#xff09;&#xff0c…

Alice与Bob-素数分解密码学

题目描述 有一个大的整数&#xff0c;98554799767&#xff0c;请分解为两个素数&#xff0c;分解后&#xff0c;小的放前面&#xff0c;大的放后面&#xff0c;合成一个新的数字&#xff0c;进行md5的32位小写哈希 def su(num):lt[]print(num,,end)while num!1:for i in rang…

DeepSeek和ChatGPT在科研课题设计和SCI论文写作中的应用

DeepSeek和ChatGPT在科研课题设计和SCI论文写作中的应用 一、DeepSeek和ChatGPT的基础理论 (理论讲解案例分析) 1.DeepSeek的技术架构 (1)DeepSeek的定义与核心目标 (2)DeepSeek的主要类型 如DeepSeek-R1、DeepSeek-V3等 (3)DeepSeek的主要创新点、优势能力以及主要应用场景 2.…

java开发——为什么要使用动态代理?

举个例子&#xff1a;假如有一个杀手专杀男的&#xff0c;不杀女的。代码如下&#xff1a; public interface Killer {void kill(String name, String sex);void watch(String name); }public class ManKiller implements Killer {Overridepublic void kill(String name, Stri…

25工程管理研究生复试面试问题汇总 工程管理专业知识问题很全! 工程管理复试全流程攻略 工程管理考研复试真题汇总

工程管理复试面试心里没底&#xff1f;别慌&#xff01;学姐手把手教你怎么应对复试&#xff01; 很多同学面对复试总担心踩坑&#xff0c;其实只要避开雷区掌握核心技巧&#xff0c;逆袭上岸完全有可能&#xff01;这份保姆级指南帮你快速锁定重点&#xff0c;时间紧迫优先背…

运维脚本——9.配置漂移检测

场景&#xff1a;检测服务器配置与基准配置的差异&#xff0c;防止未经授权的修改。 示例&#xff1a;使用Ansible Playbook对比当前配置与标准模板。 - hosts: alltasks:- name: Check SSH configuration against baselineansible.builtin.diff:path: /etc/ssh/sshd_configori…