--1.学生表
Student(S#,Sname,Sage,Ssex) --
2.课程表
Course(C#,Cname,T#)
--3.教师表
Teacher(T#,Tname)
--4.成绩表
SC(S#,C#,score) --S# 学生编号,C# 课程编号,score 分数
查询学过编号为"01"并且也学过编号为"02"的课程的同学的信息
--方法1
select Student.* from Student , SC where Student.S# = SC.S# and SC.C# = '01' and exists (Select 1 from SC SC_2 where SC_2.S# = SC.S# and SC_2.C# = '02') order by Student.S#
--方法2
select Student.* from Student , SC where Student.S# = SC.S# and SC.C# = '02' and exists (Select 1 from SC SC_2 where SC_2.S# = SC.S# and SC_2.C# = '01') order by Student.S#
--方法3
select m.* from Student m where S# in
(
select S# from
(
select distinct S# from SC where C# = '01'
union all
select distinct S# from SC where C# = '02'
) t group by S# having count(1) = 2
)
order by m.S#
这里面的1 (方法里的 Select 1 )是什么意思?
|