比较运算符来限定查询条件格式如下
where 表达式1 比较运算符 表达式2
举例
查询所有男生信息
select * from student
where ssex="男";
查询条件 | 运算符 |
比较运算符 | =、<、>、<=、>=、<>、!=、!<、!> |
范围运算符 | between and、not between and |
列表运算符 | in、not in |
字符运算符 | like、not like |
空值 | is null、is not null |
逻辑运算符 | and、or、not |
举例
查询所有成绩大于80分的学生的学号和成绩
select son as'学号',degree as '成绩'
from sc
where degree>80;
查询所有男生的学号、姓名、性别及出生日期
select sno, sname,sdept,sbirthday
from stundet
where ssex="男";
查询计算机工程系全体学生的名单
select sname
from stundet
where sdept="计算机工程系";
查询考试成绩不及格的学生的学号
select distinct sno //distinct 短语,即使一个学生有多门课程不及格,他的学号也只出现一次
from sc
where degree<60;