一.SQL语言查询选修了全部课程的学生的学号和姓名. 两种解决途径: 第一种: 我们可以表示为在SC表中某个学生选修的课程数等于C表中课程总数.相应的SQL语言如下: select S#,SNAME from S where S# in (select S# from SC group by S# --根据Sno分组,统计每个学生选修了几门课程.如果等于C表课程的总数,就是我们要找的S# having count(*) = (select count(*) from C))--统计C表中共有几门
select sname from student where not exists (select * from course where not exists (select * from sc where sno =student.sno and cno=course.cno); 最内部的 select * from sc where sno=student.sno and cno = course.cno是查询出所有已经选择过课程的学生及相应课程,select * from cour
29.查询选修编号为"3-105"课程且成绩至少高于选修编号为"3-245"的同学的Cno.Sno和Degree,并按Degree从高到低次序排序. select tname,prof from teacher where depart = '计算机系' and prof not in ( select prof from teacher where depart = '电子工程系') 30.查询选修编号为"3-105"且成绩高于选修编号为&q
33. 查询成绩比该课程平均成绩低的同学的成绩表. select * from score a where a.degree between 0 and( select avg(degree) from score b where a.cno=b.cno ) 34. 查询所有任课教师的Tname和Depart. select tname,depart from teacher where tno in( select tno from course ) 35 . 查询所有未讲课的教师的Tna
嵌套查询 一个SELECT FROM WHERE语句称为一个查询块. 嵌套查询:将一个查询块嵌套在另一个查询块的WHERE子句或者HAVING短语的条件中的查询. 注:子查询的SELECT语句中不能使用ORDER BY子句,ORDER BY子句只能对最终查询结果排序. 1.带有IN谓词的子查询: 子查询往往是一个集合. 查询与Mike在同一个系的学生: SELECT Sno,Sname,Sdept FROM Student WHERE Sdept IN (SELECT Sdept FROM
一.介绍 首先先准备表 员工表和部门表 #建表 create table department( id int, name varchar(20) ); create table employee1( id int primary key auto_increment, name varchar(20), sex enum('male','female') not null default 'male', age int, dep_id int ); #插入数据 insert into depa
egon笔记: 1 单表查询 select distinct 字段1,字段2,字段3 from 表 where 约束条件 group by 分组字段 having 过滤条件 order by 排序字段 limit n; def from(file): f=open(file) return f def where(f,条件): lines=[] for line in f: if 条件: lines.append(line) def group(): dic={ 'male':迭代器, 'fem
上机练习2 1. 启动SQL Server 2008中的 SQL Server Management Studio. 2. 针对下面三张基本表进行操作: 学生信息表(Student): 列名 数据类型 长度 是否可空 备注 学号 char 4 N PRIMARY KEY 姓名 varchar 8 N 性别 char 2 Y 男/女 出生日期 date Y 家庭地址 varchar 50 Y 身高 decimal(3,2) Y 备注 text