有数据之后就可以开始查询了,这一关主要是简单的查询:
一:SQL的书写规则:
1、SQL语句以英文分好(;)结尾;
2、SQL语句不区分关键字的大小写;
3、列名命名时不能有空格,列名不能加单引号;
4、输入符号的时候只能使用英文格式。
二:简单查询
A:开始查询
![dbb2ba5adb11c7e07639f3f9dad40a56.png](https://img-blog.csdnimg.cn/img_convert/dbb2ba5adb11c7e07639f3f9dad40a56.png)
这是个简单的开始,如果不注意书写规则,就会出现以下情况:
![1b09d09ccb5ba9aa31e3a463323f58c4.png](https://img-blog.csdnimg.cn/img_convert/1b09d09ccb5ba9aa31e3a463323f58c4.png)
看起来有什么区别?其实只是因为“姓名”和“性别”中间的逗号是中文的,然后就报错了。可见书写规则虽然简单,但是不遵守再简单也会出错。
B:用*查找全部信息
![b52fa7f1651fdc94c5b8436d0eff4aed.png](https://img-blog.csdnimg.cn/img_convert/b52fa7f1651fdc94c5b8436d0eff4aed.png)
C:为列设定别名
我英语不好,对英语没什么感觉 ,更偏爱中文的表头,所以可以用“as”来给列设定别名;
![54c0a7dc01d3cf936bcdcef387df3da1.png](https://img-blog.csdnimg.cn/img_convert/54c0a7dc01d3cf936bcdcef387df3da1.png)
D:去重
查询中删除重复项,直接用 distinct;
![77ba6fe3f0a496ed8071345489f094a4.png](https://img-blog.csdnimg.cn/img_convert/77ba6fe3f0a496ed8071345489f094a4.png)
三:书写顺序
SQL的书写顺序:select->from->where->group by->having->order by->limit
![b744f90b440242a9e6f9aabc5a736275.png](https://img-blog.csdnimg.cn/img_convert/b744f90b440242a9e6f9aabc5a736275.png)
![da6618ae483fa21295243c4a87347707.png](https://img-blog.csdnimg.cn/img_convert/da6618ae483fa21295243c4a87347707.png)
四:运算符
A:算术运算符
加减乘除,查询score表的成绩,使用除法运算符化为百分比形式
![44e5c556f3c1e6c52bc5494e7b0a5fd3.png](https://img-blog.csdnimg.cn/img_convert/44e5c556f3c1e6c52bc5494e7b0a5fd3.png)
B:比较运算符
比较运算,主要包括相等=、不等于<>、大于>、大于等于>=、小于<、小于等于<=;感觉回去了小学,重新开始学习大小多少的比较,比如找出score数据中,成绩大于70的成绩
![9d957d6d9f1605cb4d3b109c9c901f59.png](https://img-blog.csdnimg.cn/img_convert/9d957d6d9f1605cb4d3b109c9c901f59.png)
C:逻辑运算符
not 是否定这个条件,指这个条件的反面,
and 运算符两个条件都需要满足,or运算符两个条件只需满足一个,in是or的简单写法,
between 是筛选位于两个数据之间的数据,
![85a609fa4c7eb855da1ea5b1e159e6fd.png](https://img-blog.csdnimg.cn/img_convert/85a609fa4c7eb855da1ea5b1e159e6fd.png)
![4bafb9058ee1eb6a83f0244f538ccf9b.png](https://img-blog.csdnimg.cn/img_convert/4bafb9058ee1eb6a83f0244f538ccf9b.png)
![caa5174f34086a32b40fbbd6f28fccf6.png](https://img-blog.csdnimg.cn/img_convert/caa5174f34086a32b40fbbd6f28fccf6.png)
![50fb5aace0f60b2211e7ecabf1b865b6.png](https://img-blog.csdnimg.cn/img_convert/50fb5aace0f60b2211e7ecabf1b865b6.png)
D:模糊查询
like 是对数据进行模糊筛选查询
%表示任意字符串
_1个下划线表示任意1个字符
![f477d7db82b8fce097116565b61780d0.png](https://img-blog.csdnimg.cn/img_convert/f477d7db82b8fce097116565b61780d0.png)
![496af75e1cdc650c052e25217641dac7.png](https://img-blog.csdnimg.cn/img_convert/496af75e1cdc650c052e25217641dac7.png)
![394970e401bd0a8b2be3d37c36b9b6d9.png](https://img-blog.csdnimg.cn/img_convert/394970e401bd0a8b2be3d37c36b9b6d9.png)
![3b2e35bb15ec81bb15cd8bcaed738ae9.png](https://img-blog.csdnimg.cn/img_convert/3b2e35bb15ec81bb15cd8bcaed738ae9.png)
这一关简单的查询就到这里,准备下一关了,冲啊!!