- 论坛徽章:
- 0
|
create table student
(
s# varchar(50)primary key,
sname varchar(50),
sage int,
sex varchar(2)check(sex in(\'男\',\'女\')))
insert into student values(\'s0001\',\'夏一\',\'20\',\'男\')
insert into student values(\'s0002\',\'夏二\',\'21\',\'女\')
insert into student values(\'s0003\',\'夏三\',\'22\',\'男\')
insert into student values(\'s0004\',\'夏四\',\'23\',\'女\')
insert into student values(\'s0005\',\'夏五\',\'24\',\'男\')
insert into student values(\'s0006\',\'夏六\',\'25\',\'女\')
exec sp_helpconstraint student
create table course(
c# varchar(50) primary key,
cname varchar(50),
T# varchar(50))
insert into course values(\'001\',\'课程一\',\'t0001\')
insert into course values(\'002\',\'课程二\',\'t0004\')
insert into course values(\'003\',\'课程三\',\'t0004\')
insert into course values(\'004\',\'课程四\',\'t0001\')
insert into course values(\'005\',\'课程五\',\'t0003\')
insert into course values(\'006\',\'课程六\',\'t0002\')
insert into course values(\'007\',\'课程七\',\'t0006\')
insert into course values(\'008\',\'课程八\',\'t0006\')
create table teacher(
T# varchar(50)primary key,
tname varchar(50))
insert into teacher values(\'t0001\',\'李一\')
insert into teacher values(\'t0002\',\'李二\')
insert into teacher values(\'t0003\',\'张一\')
insert into teacher values(\'t0004\',\'吴一\')
insert into teacher values(\'t0005\',\'吴二\')
insert into teacher values(\'t0006\',\'叶平\')
insert into teacher values(\'t0007\',\'叶一\')
insert into teacher values(\'t0008\',\'叶二\')
create table sc(
s# varchar(50),
c# varchar(50),
scoce float,
primary key(s#,c#))
insert into sc values(\'s0001\',\'001\',60)
insert into sc values(\'s0001\',\'002\',70)
insert into sc values(\'s0001\',\'003\',80)
insert into sc values(\'s0002\',\'001\',61)
insert into sc values(\'s0002\',\'002\',71)
insert into sc values(\'s0002\',\'003\',81)
insert into sc values(\'s0002\',\'004\',91)
insert into sc values(\'s0002\',\'005\',59)
insert into sc values(\'s0003\',\'001\',80)
insert into sc values(\'s0003\',\'007\',81)
insert into sc values(\'s0004\',\'001\',82)
insert into sc values(\'s0004\',\'008\',83)
insert into sc values(\'s0005\',\'007\',81)
insert into sc values(\'s0005\',\'008\',82)
insert into sc values(\'s0006\',\'006\',71)
insert into sc values(\'s0006\',\'007\',81)
insert into sc values(\'s0006\',\'008\',91)
四个表,
作业就是查询 同时学习 老师\'李平\'所有课程的同学名单
我试过了几个方法,都没找到正确的方法
select Student.s#,student.sname from Student , SC , Course , Teacher
where Student.S# = SC.S# and SC.C# = Course.C# and Course.T# = Teacher.T# and Teacher.Tname = \'叶平\'
order by Student.S#
|
|