![9bbb33f6abdf37df10cfa4212ad7d4d9.png](https://img-blog.csdnimg.cn/img_convert/9bbb33f6abdf37df10cfa4212ad7d4d9.png)
1.基本的查询语句练习
select 语句
select <列名1><列名2>,... ...
<表名>;
查询结果中列顺序与select子句中列顺序一样,查询多个列时,用英文逗号分开
![bb279b8c9ca1960aeb6c10401986d67e.png](https://img-blog.csdnimg.cn/img_convert/bb279b8c9ca1960aeb6c10401986d67e.png)
星号(*):查询出全部列
![5b53d10897b3dc72ea7946cc0c55d1c0.png](https://img-blog.csdnimg.cn/img_convert/5b53d10897b3dc72ea7946cc0c55d1c0.png)
as:为列设定别名
![dc5da4e66fc0f43f93d21f0c577de951.png](https://img-blog.csdnimg.cn/img_convert/dc5da4e66fc0f43f93d21f0c577de951.png)
distinct: 删除重复数据
![acd34c4733489363f2a0d2290c143a35.png](https://img-blog.csdnimg.cn/img_convert/acd34c4733489363f2a0d2290c143a35.png)
distinct用在多列之前,表示这列的数据都相同时才会删除,只能用在第一个列名出现的前面
![00f327d5b07f614aa494b864d9984031.png](https://img-blog.csdnimg.cn/img_convert/00f327d5b07f614aa494b864d9984031.png)
2.指定查询条件
sql运行顺序:
select子句最后运行
其他子句按书写顺序运行
① from从哪张表中查找数据
②where查询出符合条件的行
③从查询出的行中选取出select语句指定的列
![d57411f189edc5b3384c2dac8ce02338.png](https://img-blog.csdnimg.cn/img_convert/d57411f189edc5b3384c2dac8ce02338.png)
3.注释和sql语句注意事项
-- 单行注释
/*多行注释*/
4.运算符
- 算术运算符
![53a33b9ddb699a47ae7a7892cc79e293.png](https://img-blog.csdnimg.cn/img_convert/53a33b9ddb699a47ae7a7892cc79e293.png)
5+null=null
![d44ce6d093eb28cdef6895958fa23909.png](https://img-blog.csdnimg.cn/img_convert/d44ce6d093eb28cdef6895958fa23909.png)
- 比较运算符
![a6318644ca757512d1ba019f05ecafcf.png](https://img-blog.csdnimg.cn/img_convert/a6318644ca757512d1ba019f05ecafcf.png)
字符串的比较按照字典顺序进行排序
![264bece6dee15958464a68b004fc3b5c.png](https://img-blog.csdnimg.cn/img_convert/264bece6dee15958464a68b004fc3b5c.png)
![2498e7c48c8b9f48d64792183b01505c.png](https://img-blog.csdnimg.cn/img_convert/2498e7c48c8b9f48d64792183b01505c.png)
- 逻辑运算符
![755d30a2aa57f81bbf97d10cfd78225d.png](https://img-blog.csdnimg.cn/img_convert/755d30a2aa57f81bbf97d10cfd78225d.png)
![cf4353451e14748aa57e8990f5cedd6d.png](https://img-blog.csdnimg.cn/img_convert/cf4353451e14748aa57e8990f5cedd6d.png)
![85e6a2947b4354ef49afdf876c349705.png](https://img-blog.csdnimg.cn/img_convert/85e6a2947b4354ef49afdf876c349705.png)
![9cae7c7af53656725c6c6b1f29e05bc4.png](https://img-blog.csdnimg.cn/img_convert/9cae7c7af53656725c6c6b1f29e05bc4.png)
![dc347af72ce9e8f0d9fc6d9fa53ac232.png](https://img-blog.csdnimg.cn/img_convert/dc347af72ce9e8f0d9fc6d9fa53ac232.png)
![67eaf13d610c8bc89edfe7ca16609ce6.png](https://img-blog.csdnimg.cn/img_convert/67eaf13d610c8bc89edfe7ca16609ce6.png)
![0b8205de3e86cbafa1ff48f4e0c081fa.png](https://img-blog.csdnimg.cn/img_convert/0b8205de3e86cbafa1ff48f4e0c081fa.png)
![e2b085a3d29f78ba71b9401adaef447a.png](https://img-blog.csdnimg.cn/img_convert/e2b085a3d29f78ba71b9401adaef447a.png)
![8529c38e5fbcfcef962de02451b8ac05.png](https://img-blog.csdnimg.cn/img_convert/8529c38e5fbcfcef962de02451b8ac05.png)
![391b308d37fc38e187035e9601e7c990.png](https://img-blog.csdnimg.cn/img_convert/391b308d37fc38e187035e9601e7c990.png)
5.字符串模糊查询
like:字符串模糊查询
%表示任意字符串
![217bb4945a17c260622a0b6485992249.png](https://img-blog.csdnimg.cn/img_convert/217bb4945a17c260622a0b6485992249.png)
![4b2d0c748fc3b36550a14495cca04f61.png](https://img-blog.csdnimg.cn/img_convert/4b2d0c748fc3b36550a14495cca04f61.png)
![88dd4a6c5093165aadbf435dc1eb6dbf.png](https://img-blog.csdnimg.cn/img_convert/88dd4a6c5093165aadbf435dc1eb6dbf.png)
_1个下划线表示任意1个字符
![432d0439a34c307893129f988f258962.png](https://img-blog.csdnimg.cn/img_convert/432d0439a34c307893129f988f258962.png)
SQL的书写规则
- SQL语句以英文分号结尾
- SQL语句不区分关键字的大小写
- 列名不能加单引号,不能有空格
- 输入符号的时候只能使用英文的
SQLZOO练习
![269678158692d37753ae5f8a1d8ca885.png](https://img-blog.csdnimg.cn/img_convert/269678158692d37753ae5f8a1d8ca885.png)
![ad014f6f5c694f359903f3fb0520e989.png](https://img-blog.csdnimg.cn/img_convert/ad014f6f5c694f359903f3fb0520e989.png)
![98049471425ad0100110911bbfc9c153.png](https://img-blog.csdnimg.cn/img_convert/98049471425ad0100110911bbfc9c153.png)
![213f162d08c6516409e36b71ffd0fcd7.png](https://img-blog.csdnimg.cn/img_convert/213f162d08c6516409e36b71ffd0fcd7.png)
![ce621994f737ec103ce38c6ae77aa1d3.png](https://img-blog.csdnimg.cn/img_convert/ce621994f737ec103ce38c6ae77aa1d3.png)
![f9448ae11dfa9d43d5b45caa48156234.png](https://img-blog.csdnimg.cn/img_convert/f9448ae11dfa9d43d5b45caa48156234.png)
![8431010ed27dc8b08564364079969e24.png](https://img-blog.csdnimg.cn/img_convert/8431010ed27dc8b08564364079969e24.png)
![2965e52139c669cf3b13f701cfd262e3.png](https://img-blog.csdnimg.cn/img_convert/2965e52139c669cf3b13f701cfd262e3.png)
![104ce0880120b751a9c5e8e5f37ac957.png](https://img-blog.csdnimg.cn/img_convert/104ce0880120b751a9c5e8e5f37ac957.png)
![88bd2d5a5fea2bbe80e71512cb3648ed.png](https://img-blog.csdnimg.cn/img_convert/88bd2d5a5fea2bbe80e71512cb3648ed.png)
![729207451405dbe317b17241a4cb7d58.png](https://img-blog.csdnimg.cn/img_convert/729207451405dbe317b17241a4cb7d58.png)
![f225def62e552a082260d48162769a79.png](https://img-blog.csdnimg.cn/img_convert/f225def62e552a082260d48162769a79.png)
![e29e49893054a1a7066d67f2c77da467.png](https://img-blog.csdnimg.cn/img_convert/e29e49893054a1a7066d67f2c77da467.png)
![1bde5b935f5a9be8fd7a4fb831478078.png](https://img-blog.csdnimg.cn/img_convert/1bde5b935f5a9be8fd7a4fb831478078.png)
![d9abb4cdef0ad608023ad18222c88730.png](https://img-blog.csdnimg.cn/img_convert/d9abb4cdef0ad608023ad18222c88730.png)
![7a26b41da696fecdc7700a41d10ac521.png](https://img-blog.csdnimg.cn/img_convert/7a26b41da696fecdc7700a41d10ac521.png)
![7f843fc7c0d26d0542c451cd999592a8.png](https://img-blog.csdnimg.cn/img_convert/7f843fc7c0d26d0542c451cd999592a8.png)