一、查询所有字段
1.select+字段
2.select*from+你要查询的表(*:通配符,可以查询表中所有字段)
二、指定字段查询
1.select+字段+from+表
三、避免重复数据查询
distinct 关键字可以避免重复
1.select distinct+字段 from+表
四、为表和字段取别名
as'别名'
1.select 字段 as'别名',字段 as'别名' from 表
五、条件查询
1.比较运算符、逻辑运算符
>、<、=、!=、<>、>=、<=、&&(and)、||(or)、!(not)、xor
加在where后面 select+字段+from+表+where+条件
2.带IN关键字
IN关键字可以判断某个字段的值是否在指定的集合中,语法 in(元素1、元素二...)
select+字段+from+表+where+字段+in( );
3.带 between and关键字
判断某个字段是否在指定范围内,语法:between 取值一 and 取值二
select+字段+from+表+where+字段 between 取值一 and 取值二;
四、带is null关键字
判断字段的值是否为空,语法:is null
select+字段+from+表+where+字段 is null;
五:带like关键字
可以匹配字符串是否相等,语法:like "字符串" (字符串必须加单引号或者双引号)
%:可以代表任意长度的字符串
_:只能代表单个字符
1.select+字段+from+表+where+字段 like' '(" ");
2.select+字段+from+表+where+字段 like'x%'('%x');
3.select+字段+from+表+where+字段 like'_x'('x_');
六、高级查询
1.分组查询
语法:group by+字段名 [having]
select+字段+from+表+group by+字段 having+限制条件
限制数量:select+字段+from+表+group by+字段 having+count();
2.排序
语法:order by=字段名
select+字段+from+表+order by+字段
3.聚合函数
1.记录条数:count()
2.求和:sum()
3.平均:avg()
4.最大、最小:max()、min()
很多查询语句都是可以使用在同一个语句当中的。灵活使用即可。