23-10 条件查询

--------------------带条件查询---------------------
--select  列
--from  表
--where  条件


--查询没有及格的学生的学号(假设:数学或英语,只要有一门没有及格就叫做没有及格)
select tsId from TblScore 
select tsId from TblScore where tEnglish<60 or tMath<60


--查询年龄在20-30岁之间的男学生(包含20和30)
select * from TblStudent 
select * from TblStudent where tsage>=20 and tsage<=30 and tsGender=''

--Between...and ...   在...之间,(闭区间,包含两个端点值)
 select * from TblStudent where between 20 and 30 and tsGender=''

 --查询math成绩在80-90分之间的所有学生
 select * from TblScore where tsmath between 80 and 90



 ------------------
select *  from TblStudent
--查询出所有班级Id为3,4,5的那些学生
select *  from TblStudent where tsclassId=3 or tsclassId=4 or tsclassId=5
select *  from TblStudent where tsclassId in (3,4,5)
--对于in或者or 查询,如果查询中的条件是连续的几个数字,最好使用>=  <= 或者between...and...,不用使用or 或者in,提高效率
select *  from TblStudent where tsclassId>=3 and tsclassId<=5

 

posted @ 2017-07-18 08:53  Strugglinggirl  阅读(171)  评论(0编辑  收藏  举报