50个查询系列-第11个查询:查询至少有一门课与学号为“1001”的同学所学相同的同学的学号和姓名;


select distinct( tblstudent.StuId) from tblstudent ,

tblscore
where  tblscore.CourseId
 in
(
select tblscore.CourseId from tblscore where tblscore.StuId='1001' 
)
and tblstudent.StuId=tblscore.StuId

  答案提供两种方法;

1:

Select DistInct st.StuId,StuName From tblStudent st
  Inner Join tblScore sc ON st.StuId=sc.StuId
   Where sc.CourseId IN (Select CourseId From tblScore Where StuId='1001')

2:

 ------嵌套子查询
 Select StuId,StuName From tblStudent
  Where StuId In
  (
   Select Distinct StuId From tblScore Where CourseId In (Select CourseId From tblScore Where StuId='1001')
  )

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM