![c8919e60f60f7102a0d70b4cca4e18fe.png](https://i-blog.csdnimg.cn/blog_migrate/7eda0442b490b1b7e9620c5cfd40d4cf.jpeg)
SQL简单查询学习,主要了解以下知识点:
- 基本查询语句;
- 定向查询条件;
- 注释和sql语句注意事项;
- 运算符:算术运算符、比较运算符和逻辑运算符;
- 字符串的模糊查询;
![c94bfca851bc5f4010241a1b32ddd2eb.png](https://i-blog.csdnimg.cn/blog_migrate/910757943903f772f7ca777ce06ed621.jpeg)
实操练习:
1、星号(*)——查询出全部列:
select * from student
![b2a906ade2c7db96a2d619e1c2a32585.png](https://i-blog.csdnimg.cn/blog_migrate/765753d4f05a9eb0fdc7bf73bc743726.png)
2、as——为列设定别名:
select 姓名 as s_name, 性别 as '人类行别' from student;
![b3bed24a3294e75762aecb238885b7ba.png](https://i-blog.csdnimg.cn/blog_migrate/febb38c5267a2925b2df3316f8e28e5c.png)
3、distinct——删除重复项:
select distinct 姓名 from student;
![02df56a321921e2cfe88ca82c089c656.png](https://i-blog.csdnimg.cn/blog_migrate/a728626001738870f8021c76ef59d0a3.png)
4、where——指定查询条件:
select 姓名,学号 from student where 姓名='猴子';
![d3acee14cee733bdc47ecb2c50f2de6d.png](https://i-blog.csdnimg.cn/blog_migrate/36250e43423bf23e78e79f5de48bc8dd.png)
5、运算符:
- 算术运算符:
select 学号,成绩,成绩/100 as '百分比成绩' from score;
![12f606cf02d04e59284d251675270fbd.png](https://i-blog.csdnimg.cn/blog_migrate/99afe4e1af1f98c23bd7546b975a5c0f.png)
- 比较运算符:
select 学号,成绩 from score where not 成绩>=60;
select 学号,成绩 from score where 成绩<60;
![6a08ce353991965ca8cdca9f5b415bd5.png](https://i-blog.csdnimg.cn/blog_migrate/c835f3ad7e6bb6860b67df4c03ee28fc.png)
select 学号,成绩 from score where 成绩<60;
![b40fa8e8689e66c54385b26609bfb3af.png](https://i-blog.csdnimg.cn/blog_migrate/e1a1a6bb57f96874aac117a0916951a6.png)
select 姓名,出生日期 from student where 出生日期<'1991-01-01';
![25f2bb131c0151a7418d0d74c17a0844.png](https://i-blog.csdnimg.cn/blog_migrate/e40bcd858e0e9443f8f4578d9cdfe514.png)
- 逻辑运算符:
select 学号,成绩 from score where 成绩>=60 and 成绩<=90;
![0606c940192b1c4c05dc138c8afb93dc.png](https://i-blog.csdnimg.cn/blog_migrate/1029a6e35255fc4d1b2d38d09c57976d.png)
select 姓名,性别 from student where 性别='男' and (姓名='猴子' or 姓名='马云');
![4798110b37768555cbf7ea4869dce2e2.png](https://i-blog.csdnimg.cn/blog_migrate/34beff41ecdb03028db283ccca545d4c.png)
select 学号,成绩 from score where 成绩 between 60 and 90;
select学号,成绩 from score where 成绩>=60 and 成绩<=90;
![6aa8da3dfae41c6774f6c8b7d2faa355.png](https://i-blog.csdnimg.cn/blog_migrate/ab586d793bedd2996d8b669653302a3d.png)
select 姓名,性别 from student where 姓名 in('猴子','马云');
![94e0522797eb15bbe5c0621f86623406.png](https://i-blog.csdnimg.cn/blog_migrate/5cc5472486f726454feb5b34688c859c.png)
6、查询null值
select 教师号,教师姓名 from teacher where 教师姓名 is null;
![732cba203e71503edfb03bff91a077e2.png](https://i-blog.csdnimg.cn/blog_migrate/7b60877a9ae1b615726821f65f002da4.png)
select 教师号,教师姓名 from teacher where 教师姓名 is not null;
![735fecff1c0a0c26ae9e02450caf99b9.png](https://i-blog.csdnimg.cn/blog_migrate/8651f4a0a4f9d9d12348f72e8f9f413a.png)
7、模糊查询:
select * from student where 姓名 like '猴%';
![4138e8702901e7c66ad064b62c07a1b0.png](https://i-blog.csdnimg.cn/blog_migrate/1448cfa2ec53587a50208277ba0d1144.png)
select * from student where 姓名 like '%猴';
![3bc746f1cb3865afb80cd4579ae44479.png](https://i-blog.csdnimg.cn/blog_migrate/f31a5dd8db6eaffc53507ed0922bdbc6.png)
select * from student where 姓名 like '%猴%';
![695b289dcc604f1a9f5485a65f58d8bc.png](https://i-blog.csdnimg.cn/blog_migrate/4c6501f1ddd7034c14bb2d29d95b4160.png)
select * from student where 姓名 like '王__';
![d96171f2a5460639c90bbdabe2296b27.png](https://i-blog.csdnimg.cn/blog_migrate/504272d3db85b8dd650215e063d583db.png)
8、sqlzoo练习:
![16d64872cb226a2d70cfe9ccedcf9c3f.png](https://i-blog.csdnimg.cn/blog_migrate/0eafce188b6520c01aaf7362ef1b57c7.png)
![fce89570a3ab8c36f36749a976caffb4.png](https://i-blog.csdnimg.cn/blog_migrate/c9a7144e5b39f52d77eec1f89984e7e9.jpeg)
![de5a71d2b04d171d05b8751b4c347a19.png](https://i-blog.csdnimg.cn/blog_migrate/2f5ed540339576a09190e815aba64655.jpeg)