1.查询所有的数据
"*" 代表所有的列数据
select *from student;
![在这里插入图片描述](https://img-blog.csdnimg.cn/20191127232044291.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDkxNzQyOQ==,size_16,color_FFFFFF,t_70)
2.查询username的列数据
select username from student;
![在这里插入图片描述](https://img-blog.csdnimg.cn/20191127230440559.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDkxNzQyOQ==,size_16,color_FFFFFF,t_70)
3.查询id,username列数据
select id,usename from student;
4.查询某一行的数据
select id,username from student where id=3;
5.in and or 的匹配条件
in代表查询多行数据
select id,username,password from student where id in(2,3,4);
and代表与的意思
select * from stuent where id=2 and uername=“zhangsan”;
or代表或的意识
select * from student where id=1 or id=4;
6.betweeen 匹配条件(取中间查询范围值)
select * from student where id between 1 and 3;
当然也可以用字符或字符串
select * from student where usernae between a and d;
select * from student where username between “sdsds” and “sdas”;
7.like匹配条件(模糊查询)
select * from student where id like 3;
select * from student where uesrname like “%ahng%”; //字符串必须要用“%”;
8.not 匹配条件(取补集)
select * from student where username not like “%zhag%”;
select * from student where id not between 1 and 3;
9.排序
升序 order by
select * from name order by id;
mysql>
降序 order by desc
select * from student order by id desc;
10,事务,回滚
(1)begin;
(2)insert into student values(6,“zhangsan”,123123);
(3) commit;
(1)begin;
(2)insert into student values(6,“ahngsan”,321);
(3)rollback;
11.函数和聚合
(1)avg 求平均值
(2)count 求表达的项数
(3)max 求最大值
(4)min 求最小值
(5)sum 求和
select avg(scoer) from student;
select min(scoer) from student;
select max(scoer) from student;
select count(scoer) from student;
12.分组查询 gorup by
(1) select class,avg(scoer) from student group by class;
(2) select class,avg(scoer) from student where class="cla_A" group by class;
- 过滤分组 having by