一.条件查询:select * from + 表名 + where + 条件;
这里举例来说明:(均在stu表中)
1.查询年龄大于20岁的学员信息
select * from stu where age >20;
2.查询年龄大于等于20岁的学员信息
select * from stu where age >= 20;
3.查询年龄大于等于20岁并且年龄小于等于30岁的学员信息
select * from stu where age >= 20 && age <= 30;
select * from stu where age >= 20 and age >=30;
4.查询入学时间在‘1990-09-01’到‘1999-09-01’之间的学员信息(这里表中入学时间为hire_date)
select * from stu where hire_date between '1990-09-01' and '1999-09-01';
5.查询年龄等于18岁的学员信息
select * from stu where age = 18;
6.查询年龄不等于18岁的学员信息
select * from stu where age != 18;
select * from stu where age <> 18;
7.查询年龄等于18岁 或者 年龄等于20岁 或者 年龄等于22岁的学员信息
select * from stu where age = 18 or age = 20 or age = 22;
select * from stu where age in(18,20,22);
8.查询英语成绩为null的学员信息(这里表中定义的英语成绩为english)
(注意:null值比较不能用 = !=,需要使用is is not)
select * from stu where english is null;
select * from stu where english is not null;
9.select * from 试题表 where 使用场景 in('课堂测试','升级考试','阶段考试');
二.模糊查询:(1)_:代表单个任意字符(2)%:代表任意个数字符
eg1.查询姓‘马’的学员信息
select * from stu where name like '马%';
2.查询第二个字是‘花’的学员信息
select * from stu where name like '_花%';
3.查询姓名中包含‘德’的学员信息
select * from stu where name like '% 德%';