2、select b.* from sc a ,s b where a.s# =* b.s# and (a.c# <> 'C2')
一、 declare @SC table(s int,c int,GRADE int) declare @C table(c int ,CNAME varchar(10) ,TEACHER varchar(10) )insert @c select 1,'A','' union all select 2,'B','' union all select 3,'C','' insert @sc select 1,1,100 union all select 1,2,100 union all select 1,3,90 union all select 2,1,90 union all select 3,3,90select distinct a.s from @sc a ,@c b where a.C = b.C and (b.c = '1' or b.c = '2')
1、检索只选修课程号为C2和C4的学生学号 解法: select a.s# from sc a ,c b where a.C# = b.C# and (b.c# = 'C2' or b.c# = 'C4') 这不是检索选修课程号为C2或者C4的学生学号的解吗?
declare @SC table(s int,c int,GRADE int)
declare @C table(c int ,CNAME varchar(10) ,TEACHER varchar(10) )insert @c select 1,'A','' union all
select 2,'B','' union all
select 3,'C',''
insert @sc select 1,1,100 union all
select 1,2,100 union all
select 1,3,90 union all
select 2,1,90 union all
select 3,3,90select distinct a.s from @sc a ,@c b where a.C = b.C and (b.c = '1' or b.c = '2')
解法:
select a.s# from sc a ,c b where a.C# = b.C# and (b.c# = 'C2' or b.c# = 'C4')
这不是检索选修课程号为C2或者C4的学生学号的解吗?