《Database System Concepts(数据库系统概念)》第六版——第三次作业(第三章)

这些SQL查询涉及多表连接(如JOIN),条件过滤(WHERE子句),聚合函数(COUNT,MAX,SUM),分组(GROUPBY)以及子查询,主要用于数据提取和分析,例如查找特定导师的学生,计算学分加权分数,评估成绩分布,贷款和银行信息,以及员工薪资比较。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

3.1

  • b

    select distinct student.ID
    from student natural join advisor,instructor
    where instructor.ID=advisor.i_id and instructor.name="Einstein"
    
  • e

    select course_id,sec_id,count(ID)
    from section natural join takes
    where year=2009 and semester="fall"
    group by course_id,sec_id
    
  • f

    select max(sum)
    from (select count(ID) as con
    	from section natural join takes
    	where year=2009 and semester="fall"
    	group by course_id,sec_id)
    
  • g

    select course_id,sec_id
    from section natural join takes
    where count(ID)=(select max(con)
    				from (select count(ID) ans con
    					from section natural join takes
    					where year=2009 and semester="fall"
    					group by course_id,sec_id)) and year=2009 and semester="fall"
    group by course_id,sec_id	)
    					)				
    

3.2

  • a

     select count(points*credits)
     from ((takes natural join course ) join grade_points using grade
     where ID=12345
    
  • b

     select sum(points*credits) / sum(credits)
     from ((takes natural join course ) join grade_points using grade
     where ID=12345
    
  • c

     select ID,sum(points*credits) / sum(credits)
     from ((takes natural join course ) join grade_points using grade
    group by ID
    

3.5

  • a

    select ID,
    	case 
    		when score<40 then 'F'
    		when score<60 then 'C'
    		when score<80 then 'B'
    		else 'A'
    		as grade
    from marks
    
  • b

    select grade,count(ID)
    from (select ID,
    	case 
    		when score<40 then 'F'
    		when score<60 then 'C'
    		when score<80 then 'B'
    		else 'A'
    		as grade
    	from marks)
    group by grade
    

3.8

  • a

    select customer_name
    from loan natural join borrower
    where amount=0
    
  • b

    select customer_name
    from customer
    where customer_street=(select customer_street from customer where customer_name="Smith") and customer_city=(select customer_city from customer where customer_name="Smith")
    
  • c

    select distinct branch_name
    from (account natural join depositor) join customer using customer_name
    where customer_city="Harrison"
    

3.9

  • a

    select employee_name,city
    from employee natural join works
    where company_name="First Bank Corporation"
    
  • b

    select employee_name,street,city
    from employee natural join works
    where company_name="First Bank Corporation" and salary>10000
    
  • c

    select employee_name
    from employee natural join works
    where company_name<>"First Bank Corporation"
    
  • d

    select employee_name
    from employee natural join works
    where  salary > all(select salary
    					from employee natural join works
    					where company_name="Small Bank Corporation")
    
  • e

    select company_name
    from company
    where city in (select city
    				from company
    				where company_name="Small Bank Corporation")
    
  • f

    select company_name
    from works
    where count(employee_name)=(select max(con)
    				from (select count(employee_name) as con
    					from works
                        group by company_name)
                          )
    
  • g

    select company_name
    from works
    group by company_name
    having avg(salary)>(select avg(salary)
    					from works
    					where company_name="First Bank Corporation")
    

3.14

  • a

    select damage_amount
    from participated join person
    where name="John Smith"
    
第2章习题答案: 1. a) 数据定义语言(Data Definition Language,DDL)负责定义、修改和删除数据库的结构,如创建表、定义表的列、设定主键等操作。 b) 数据操作语言(Data Manipulation Language,DML)用于对数据库中的数据进行操作,如插入、查询、更新、删除等操作。 2. a) 关系模型(Relational Model)是一种用于组织数据的模型,它将数据组织为表格形式的关系,通过表格中的行和列来表示实体和属性之间的关系。 b) 实体-关系(Entity-Relationship)模型是一种用于描述现实世界中实体和它们之间关系的模型,通过实体、属性和联系的概念来表示。 3. 事务(Transaction)是指由一个或多个数据库操作组成的逻辑工作单位,它将数据库从一个一致状态转换到另一个一致状态。事务具有ACID属性,即原子性、一致性、隔离性和持久性。 4. 数据库系统的并发控制(Concurrency Control)是指在多个用户并发访问数据库时,保证数据的一致性和完整性的一系列技术和方法。常用的并发控制技术包括锁、并发控制算法和多版本并发控制。 5. a) 恢复(Recovery)是指在数据库系统发生故障时,通过一系列技术和方法将数据库从故障状态恢复到正常状态。 b) 日志(Log)是用于记录数据库操作的序列和重建数据的工具。常见的日志技术包括正向和反向恢复日志。 6. a) 数据库设计(Database Design)是指将现实世界的需求转化为数据库模式的过程,包括概念设计、逻辑设计和物理设计。 b) 数据库模式(Database Schema)是数据库的结构描述,包括表、列、键、约束等元素的定义。 7. a) 数据库安全(Database Security)是指保护数据库不被非法使用、不被篡改或窃取的一系列措施。常见的安全机制包括访问控制、身份验证和加密。 b) 数据库完整性(Database Integrity)是指保证数据库中数据的准确性和一致性的一系列约束和规则。常见的完整性约束包括主键、外键和检查约束。 8. a) 数据库视图(Database View)是基于数据库中一个或多个表的查询结果,以虚拟表的形式存储在数据库中,可以像访问普通表一样对其进行操作。 b) 数据库索引(Database Index)是用于提高数据检索性能的数据结构,通过按照某种规则将数据排序和组织起来,减少数据搜索的时间复杂度。 以上是对《数据库系统概念第六版第2章习题的回答。希望可以帮助到您!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值