Advertisement

第³章 SQL练习题-³·²²、³·²³、³·²⁴

阅读量:

3.22 不使用unique结构,重写下面的where子句:

复制代码
    where unique(select title from course)
    

若未采用unique关键字,相应的SQL语句应作如下编写:

复制代码
    where 1 >= (select count(title) from course)
    

3.23 考虑查询:

复制代码
 select course_id, semester, year, sec_id, avg(tot_cred)

    
 from takes natural join student
    
 where year = 2009
    
 group by course_id, semester, year, sec_id
    
 having count(ID) >= 2;
    
    
    
    

解释为什么在from子句中还加上与section的连接不会改变查询结果。

该SQL查询语句的功能是检索出2009年度开设的课程段中,选课人数超过两位的记录。由于takes表中的主键字段已完整包含课程段主键的相关信息,因此是否执行连接操作已无实际意义。只有在需要获取section表中除主键以外的其他属性数据时,才需考虑进行连接

全部评论 (0)

还没有任何评论哟~