1 in 子查询
1 use StudentManageDB 2 go 3 --select StudentName from Students 4 --where StudentId=(select StudentId from ScoreList where SQLServerDB>80) 5 select StudentName from Students 6 where StudentId in (select StudentId from ScoreList where SQLServerDB>80)
1 use StudentManageDB 2 go 3 select StudentId,StudentName from Students 4 where StudentId not in(select StudentId from ScoreList)
2.exist 子查询
1 use StudentManageDB 2 go 3 if exists(select * from ScoreList where CSharp<60) 4 print '本次考试内容较难' 5 else 6 print '本次考试内容适中' 7 8 --NOT EXISTS的使用 9 if not exists(select * from ScoreList where CSharp<60) 10 print '本次考试内容适中' 11 else 12 print '本次考试内容较难'
本文深入探讨了SQL中的子查询应用,包括IN子查询和EXISTS子查询的使用方法及场景,通过具体示例展示了如何从学生管理和成绩列表中筛选特定条件的学生信息。
1030

被折叠的 条评论
为什么被折叠?



