为了更好的学习这里给出基本表数据用于查询操作
create table student (id int, name varchar(20), age int, sex varchar(5),address varchar(100),math int,english int
);insert into student
(id,name,age,sex,address,math,english)
values
(1,'马云',55,'男','杭州',66,78),
(2,'马化腾',45,'女','深圳',98,87),
(3,'马景涛',55,'男','香港',56,77),
(4,'柳岩',20,'女','湖南',76,65),
(5,'柳青',20,'男','湖南',86,NULL),
(6,'刘德华',57,'男','香港',99,99),
(7,'玛德',22,'女','香港',99,99),
(8,'德玛西亚',18,'男','南京',56,65)
;
where子语句
运算符
> < <= >= <>
//查询年龄大于20岁的行信息
select * from student where age > 20;
//查询年龄小于20岁的行信息
select * from student where age < 20;
//查询年龄等于20岁的行信息
select * from student where age = 20;
//查询年龄小于等于20岁的行信息
select * from student where age <= 20;
//查询年龄大于等于20岁的行信息
select * from student where age >= 20;
//查询年龄不等于20岁的行信息
select * from student where age <> 20;
BETWEEN…AND
//查询年龄大于等于20并且小于等于30的行信息
select * from student where age between 20 and 30;
and 或 &&
//查询年龄大于等于20并且小于等于30的行信息
select * from student where age >=20 and age <= 30;
IN(集合)
//查询年龄22岁 18岁 20岁的行信息
select * from student where age in (22,18,20);
or 或 ||
//查询年龄22岁 18岁 20岁的行信息
select * from student where age = 22 or age = 18 or age = 20;
IS NULL
//查询英语弃考的
select * from student where english is null;
not 或 !
//查询英语没有弃考的
select * from student where english is not null;
LIKE (模糊查询)
查询姓马的
select * from student where name like '马%';
查询第二个字是’化’的
select * from student where name like '_化%';
查询名称是三个字的人
select * from student where name like '___';
查询姓名中包含’德’的人
select * from student where name like '%德%';
点击返回 MySQL 快速学习目录