SQL简单查询学习,主要了解以下知识点:
- 基本查询语句;
- 定向查询条件;
- 注释和sql语句注意事项;
- 运算符:算术运算符、比较运算符和逻辑运算符;
- 字符串的模糊查询;
实操练习:
1、星号(*)——查询出全部列:
select * from student
2、as——为列设定别名:
select 姓名 as s_name, 性别 as '人类行别' from student;
3、distinct——删除重复项:
select distinct 姓名 from student;
4、where——指定查询条件:
select 姓名,学号 from student where 姓名='猴子';
5、运算符:
- 算术运算符:
select 学号,成绩,成绩/100 as '百分比成绩' from score;
- 比较运算符:
select 学号,成绩 from score where not 成绩>=60;
select 学号,成绩 from score where 成绩<60;
select 学号,成绩 from score where 成绩<60;
select 姓名,出生日期 from student where 出生日期<'1991-01-01';
- 逻辑运算符:
select 学号,成绩 from score where 成绩>=60 and 成绩<=90;
select 姓名,性别 from student where 性别='男' and (姓名='猴子' or 姓名='马云');
select 学号,成绩 from score where 成绩 between 60 and 90;
select学号,成绩 from score where 成绩>=60 and 成绩<=90;
select 姓名,性别 from student where 姓名 in('猴子','马云');
6、查询null值
select 教师号,教师姓名 from teacher where 教师姓名 is null;
select 教师号,教师姓名 from teacher where 教师姓名 is not null;
7、模糊查询:
select * from student where 姓名 like '猴%';
select * from student where 姓名 like '%猴';
select * from student where 姓名 like '%猴%';
select * from student where 姓名 like '王__';
8、sqlzoo练习: