时间:2021-07-01 10:21:17 帮助过:12人阅读
-- 向students表中插入数据 insert into students values (0,‘小明‘,18,180.00,2,1,0), (0,‘小月月‘,18,180.00,2,2,1), (0,‘彭于晏‘,29,185.00,1,1,0), (0,‘刘德华‘,59,175.00,1,2,1), (0,‘黄蓉‘,38,160.00,2,1,0), (0,‘凤姐‘,28,150.00,4,2,1), (0,‘王祖贤‘,18,172.00,2,1,1), (0,‘周杰伦‘,36,NULL,1,1,0), (0,‘程坤‘,27,181.00,1,2,0), (0,‘刘亦菲‘,25,166.00,2,2,0), (0,‘金星‘,33,162.00,3,3,1), (0,‘静香‘,12,180.00,2,4,0), (0,‘郭靖‘,12,170.00,1,4,0), (0,‘周杰‘,34,176.00,2,5,0); -- 向classes表中插入数据 insert into classes values (0, "python_01期"), (0, "python_02期");
select * from 表名;
select * from students;
select id as 序号, name as 名字, gender as 性别 from students;
-- 如果是单表查询 可以省略表名 select id, name, gender from students; -- 表名.字段名 select students.id,students.name,students.gender from students; -- 可以通过 as 给表起别名 select s.id,s.name,s.gender from students as s;
在select后面列前使用distinct可以消除重复的行
select distinct 列1,... from 表名;
例:select distinct gender from students;
使用where子句对表中的数据筛选,结果为true的行会出现在结果集中
select * from 表名 where 条件;
例:
select * from students where id=1;
(1)比较运算符
例1:查询编号大于3的学生
select * from students where id>3;
select * from students where id<=4;
select * from students where name !=‘黄蓉‘;
例4:查询没被删除的学生
select * from students where is_delete=0;
例1:查询编号大于3的女学生
select * from students where id>3 and gender=‘女‘;
select * from students where id<4 or is_delete=0;
select * from students where name like ‘小%‘;
select * from students where name like ‘小_‘;
select * from students where name like ‘黄%‘ or ‘%靖‘;
select * from students where id in (1,3,8);
select * from students where id between 3 and 8;
select * from students where (id betweent 3 and 8) and gender=1;
select * from students where height is null;
select * from students where height is not null;
select * from students where height is not null and gender=‘男‘;
MySQL之查询篇(简单查询以及条件)(三)
标签:括号 com 小明 src classes sign auto 查询 png