0 插入数据

  • people.sql ```sql create table people( id int primary key auto_increment, name varchar(10), age int, height decimal(5,2), gender enum(“男”, “女”, “中性”, “保密”) default “保密”, cls_id int, is_deleted tinyint(1) default 0 );

insert people values (1, “小明”, 18, 180, “女”, 1, 0), (2, “小月月”, 18, 180, “女”, 2, 0), (3, “彭于晏”, 29, 185, “男”, 1, 0), (4, “刘德华”, 59, 175, “男”, 2, 0), (5, “黄蓉”, 38, 160, “女”, 1, 0), (6, “凤姐”, 28, 150, “保密”, 2, 0), (7, “王祖贤”, 53, 172, “女”, 1, 0), (8, “周杰伦”, 36, null, “男”, 1, 0), (9, “程坤”, 27, 181, “男”, 2, 0), (10, “刘亦菲”, 25, 166, “女”, 1, 0), (11, “金星”, 33, 162, “中性”, 3, 0), (12, “静香”, 12, 150, “女”, 4, 0), (13, “郭靖”, 12, 170, “男”, 4, 0), (14, “周杰”, 34, 181, “男”, 5, 0);

  1. - class.sql
  2. ```sql
  3. create table class(
  4. id int primary key auto_increment,
  5. name varchar(4)
  6. );
  7. insert class values
  8. (1, "A班"),
  9. (2, "B班"),
  10. (3, "C班");

image.png

1 条件查询

select * from people where age >18 and age <40;
image.png

2 模糊查询

(1) like匹配

  • _ 相当于一个任意字符
  • % 相当于0个或多个任意字符

select * from people where name like "小%";
image.png
select * from people where name like "__";
image.png
select * from user where zone == ‘086’ && mobile like “%6858”;

(2) rlike正则匹配

select * from people where name rlike "^周.*";
image.png

3 范围查询

(1) 离散范围

select * from people where age in (12,18,34);
image.png

(2) 连续范围

select * from people where age between 18 and 34;
image.png

4 判空查询

select * from people where height is null;
image.png
select * from people where height is not null;
image.png