赞
踩
- select * from 表名;
- 例:
- select * from students;
- select 列1,列2,... from 表名;
- 例:
- select name 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 列1,... from 表名;
- 例:
- select distinct gender from students;
使用where子句对表中的数据筛选,结果为true的行会出现在结果集中
- select * from 表名 where 条件;
- 例:
- select * from students where id=1;
例1:查询编号大于3的学生
select * from students where id > 3;
例2:查询编号不大于4的学生
select * from students where id <= 4;
例3:查询姓名不是“黄蓉”的学生
select * from students where name != '黄蓉';
例4:查询没被删除的学生
select * from students where is_delete=0;
例5:查询编号大于3的女同学
select * from students where id > 3 and gender=0;
例6:查询编号小于4或没被删除的学生
select * from students where id < 4 or is_delete=0;
例7:查询姓黄的学生
select * from students where name like '黄%';
例8:查询姓黄并且“名”是一个字的学生
select * from students where name like '黄_';
例9:查询姓黄或叫靖的学生
select * from students where name like '黄%' or name like '%靖';
例10:查询编号是1或3或8的学生
select * from students where id in(1,3,8);
例11:查询编号为3至8的学生
select * from students where id between 3 and 8;
例12:查询编号是3至8的男生
select * from students where (id between 3 and 8) and gender=1;
例13:查询没有填写身高的学生
select * from students where height is null;
例14:查询填写了身高的学生
select * from students where height is not null;
例15:查询填写了身高的男生
select * from students where height is not null and gender=1;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。